AI for Environmental Data Science
Prompting Fundamentals
MEDS AI Workshop Series | #2 (2026-11-09)
Annie Adams, Kat Le
Part 1 · How the model reads your prompt
Tokens, context windows and other LLM vocabulary
Part 2 · Prompting fundamentals
Context, specificity, iteration, verification
Part 3 · Same data, three roles
The 2020 NYC Park Squirrel Census under three roles
Activity · Prompt makeover
Four rounds: weak prompt → strong prompt → verified code
Part 4 · From prompts to agents
Agentic coding in Claude Code
By the end you can…
Part 1
How the model reads your prompt
LLM vocabulary, and what an AI assistant can and can’t see
Token
The unit a model reads and writes; a word or part of a word
Context window
The maximum number of tokens the model can work with at once
Prompt
Everything you send the model: your question, pasted data, instructions
System prompt
Hidden instructions the tool gives the model before your prompt
Hallucination
Confident output that is false: a made-up function, column or citation
Non-determinism
The same prompt can give different answers each time you run it
Models don’t read words or characters. They read tokens.
Whichparkhadthemostsquirrelsightingsin2020?
Illustrative split. The exact tokens depend on each model’s tokenizer.
Rules of thumb (English text)
Why it matters for data work
glimpse() + 5 rows: a few hundred tokensThe model’s working memory for one request, measured in tokens. Everything below shares it:
System promptAttached filesChat historyYour promptResponse
What happens as it fills
What to do
Note
Window sizes vary widely by model and tool, and change often.
The model answers using only what’s in its context window for this request.
Usually in context
@-mentioned files)glimpse())Usually not in context
Tip
Long chats drift. When the model starts forgetting constraints, start a fresh chat with a short summary of what matters.
It only knows what’s in context
glimpse() output, column names, a few sample rowsIt predicts plausible text, not truth
Four Tips
Models are trained to be helpful, which can tip into sycophancy: following your framing even when it’s wrong (Sharma et al., 2023).
Leading prompt
“Why is fur color such a strong predictor of how squirrels react to people?”
Assumes the effect exists. You’ll likely get an explanation, not a check.
Neutral prompt
“Is there evidence in this data that fur color is related to how squirrels react to people? What would make that comparison unreliable?”
Asks for evidence and limitations.
Important
Ask questions that the data could answer “no” to.
Socratic Prompting
The neutral prompt above is an example of Socratic prompting. Instead of telling the model what to find, ask it what the evidence would need to look like.
Part 2
Prompting fundamentals
Context · specificity · iteration · verification
Context I’m working with the 2020 NYC Park Squirrel Census in R. One row = one squirrel sighting. Columns include fur color, location, height and free-text activities.
Task Write a cleaning script for the activities column.
Constraints Use tidyverse. Don’t drop or overwrite any original values; put derived columns next to the originals.
Output One R chunk, then a list of every value you couldn’t parse.
Check Before writing code, list your assumptions and ask me about anything ambiguous.
Note
Context doesn’t have to live in every prompt. Recall from our last workshop that a system prompt or project pre prompt can carry context so you don’t have to repeat it each time.
| Fundamental | Weak prompt | Stronger prompt |
|---|---|---|
| Context | “Clean this data” | “This is the 2020 NYC Park Squirrel Census, one row per squirrel sighting” |
| Role / audience | (none) | “I’m a data manager preparing this for a public archive” |
| Task + constraints | “Make a plot” | “Use ggplot2, colorblind-safe palette, one plot per park” |
| Output format | Not specifying | “Return a single R chunk plus 3 bullet caveats” |
| Surface assumptions | (none) | “Before writing code, list your assumptions about each column” |
| Invite pushback | (none) | “If my approach is flawed, say so before writing code” |
The last two rows matter most
Models fill gaps silently. Asking for assumptions and pushback is how you catch data loss before it happens.
The model can’t see your data frame. Give it the structure, not the whole dataset.
Do
Don’t
1 · Plan → 2 · Code one step → 3 · Run → 4 · Review → repeat
Instead of…
“Clean the data, fit a model and make five plots.”
Try…
“First, propose a plan in 4–6 steps. Don’t write code yet.”
Tip
Each step should be small enough that you can check it.
AI-written cleaning code can run perfectly and still lose data. Check it.
Prompts that help
Dobariya & Kumar (2025) gave ChatGPT-4o 50 MC questions, each prefixed 5 ways (10 runs each, differences statistically significant):
| Tone | Accuracy |
|---|---|
| Very polite | 80.8% |
| Polite | 81.4% |
| Neutral | 82.2% |
| Rude | 82.8% |
| Very rude | 84.8% |
. . .
Example prefixes add to the questions: :
So is rudeness helping, or does adding any filler hurt?
The authors flag that prompt length may matter more than tone.
Tip
Be direct and skip the filler.
Part 3
Same data, three roles
The 2020 NYC Park Squirrel Census
Adapted from A. Dillman, Yes, And… AI in Your IDE, posit::conf(2026)
72 volunteer “Squirrel Sighters”
433 squirrel sightings
24 parks in Manhattan and Brooklyn
Source: The Squirrel Census / NYC Open Data, 2020 Park Squirrel Census
Each AI session got the same data and the same prompt, changing only the role:
“I am [role]. Clean this dataset for me.”
DM
Data manager
DS
Data science student
ENV
Environmental researcher
Adapted from A. Dillman, Yes, And… AI in Your IDE, posit::conf(2026)
Different roles yielded different methods to clean the data.
The four methods used were:
Adapted from A. Dillman, Yes, And… AI in Your IDE, posit::conf(2026)
What happened
How to prevent it
Goal: turn a weak prompt into a strong one, and see how the results change.
Round 1 · 3 min
Weak prompt
Baseline: see what you get
Round 2 · 5 min
Add context + constraints
Write a complete prompt
Round 3 · 5 min
Assumptions first
Make the model show its assumptions
Round 4 · 5 min
Verify
Check the code against the data
Setup
Download and unzip the activity materials to get started on the activity. Open the folder in Positron, and open claude.ai in your browser or the Claude desktop app.
Do this before Round 1:
activity-starter.qmd in RStudio or Positron. It loads the data and defines check_cleaning()You’re ready when glimpse(squirrels) runs without error.
Steps:
dplyr::glimpse(squirrels) and copy the outputabove_ground_height_in_feet column.clean_r1 variable assignment section of activity-starter.R and run itSteps:
dplyr::glimpse(squirrels) and copy the outputI’m analyzing the 2020 NYC Park Squirrel Census in R with the tidyverse. One row = one squirrel sighting. Here is the
glimpse()output: [paste]The
above_ground_height_in_feetcolumn records how far above ground each squirrel was observed, but values are messy — some are ranges (e.g. ‘6–18’), some are text, some are blank.Write code that adds a new numeric column. Keep the original column unchanged. Return one R chunk.
clean_r2 variable assignment section of activity-starter.R and run itSteps:
Before writing any code, describe the different value formats or patterns you observe in the above_ground_height_in_feet column (e.g. plain numbers, ranges, text annotations), how you plan to handle each one, and anything you’re unsure about. Wait for my answer.
clean_r3 variable assignment section of activity-starter.R and run itSteps:
activity-starter.R, run the check on your Round 1 and Round 3 outputs, using the cleaned data frame:above_ground_height_in_feet does your code turn into NA? List them.”check_cleaning() showed?In activity-starter.R, and worth keeping for any AI-written cleaning code:
check_cleaning <- function(before, after, col) {
if (!col %in% names(after)) stop("Column '", col, "' was renamed or dropped")
tibble::tibble(
rows_before = nrow(before),
rows_after = nrow(after),
na_before = sum(is.na(before[[col]])),
na_after = sum(is.na(after[[col]])),
values_before = dplyr::n_distinct(before[[col]]),
values_after = dplyr::n_distinct(after[[col]])
)
}Tip
If na_after > na_before, the code turned real observations into missing data. Did the model warn you?
| Round 1 | Round 2 | Round 3 | |
|---|---|---|---|
| Rows kept? | |||
| Original column kept? | |||
| New NAs created | |||
| Model told you what it changed? | |||
| Code you’d actually use? |
Debrief (5 min)
Part 4
From prompts to agents
In the activity, every round you:
glimpse() outputImportant
What if the assistant could run the code and the check itself?
That’s agentic coding.
Chat assistant
You run the loop.
Coding agent (e.g. Claude Code)
It runs the loop. You stay the reviewer.
Tip
An agent can act on your files, so the fundamentals matter more, not less.
AI for EDS · Prompting Fundamentals