AI for Environmental Data Science

Prompting Fundamentals

MEDS AI Workshop Series | #2 (2026-11-09)

Annie Adams, Kat Le

Today’s plan

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…

  • Write a prompt with context, constraints and an output format
  • Get the model to state its assumptions
  • Check AI-written code against the data before you trust it

Part 1

How the model reads your prompt

LLM vocabulary, and what an AI assistant can and can’t see

Terms to know

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

Tokens: how the model reads text

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)

  • One token is roughly ¾ of a word
  • Common words are one token; rare words, numbers and code split into several
  • Tools limit and bill usage in tokens

Why it matters for data work

  • A pasted CSV costs tokens for every value
  • glimpse() + 5 rows: a few hundred tokens
  • A full dataset can fill most of the window, leaving less room for your instructions

The context window

The model’s working memory for one request, measured in tokens. Everything below shares it:

System promptAttached filesChat historyYour promptResponse

What happens as it fills

  • The response has to fit too
  • Older messages may be summarized or dropped
  • Details buried in a long chat get less attention

What to do

  • Send structure, not raw data
  • One task per chat; start fresh when it drifts
  • Restate key constraints in the new chat

Note

Window sizes vary widely by model and tool, and change often.

What’s in the context window?

The model answers using only what’s in its context window for this request.

Usually in context

  • Your prompt and the chat so far
  • Files or selections your IDE assistant attaches (open editor, @-mentioned files)
  • Output you paste in (errors, glimpse())

Usually not in context

  • The actual values in your data frame
  • Your project’s goals, field conventions, data-collection quirks
  • What you decided in a different chat

Tip

Long chats drift. When the model starts forgetting constraints, start a fresh chat with a short summary of what matters.

What the model knows (and doesn’t)

It only knows what’s in context

  • It hasn’t seen your data unless you show it
  • Paste glimpse() output, column names, a few sample rows
  • Say what the data is: source, units, one row = ?

It predicts plausible text, not truth

  • Code that runs ≠ code that’s correct
  • It fills gaps with assumptions, silently
  • It tends to agree with your framing, even when it’s wrong

Four Tips

  1. Give context: data, goal, audience
  2. Be specific: tools, constraints, output format
  3. Iterate in small steps: one task per prompt, then review
  4. Verify: run it, check the data, ask for its assumptions

The model tends to agree with you

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

Anatomy of a good prompt

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.

Prompting fundamentals

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.

Show the model your data (safely)

The model can’t see your data frame. Give it the structure, not the whole dataset.

dplyr::glimpse(squirrels)          # column names, types, first values
head(squirrels, 5) |> knitr::kable() # a few example rows
dput(head(squirrels, 5))           # reproducible snippet it can run

Do

  • Paste schema + a few rows
  • Describe units and how the data was collected
  • Mention known messiness

Don’t

  • Paste sensitive or restricted data into tools your institution hasn’t approved
  • Assume the model knows your column meanings

Iterate in small steps

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.

Verify before you trust

AI-written cleaning code can run perfectly and still lose data. Check it.

n_before <- nrow(squirrels)
clean    <- clean_squirrels(squirrels)   # AI-written function

stopifnot(nrow(clean) == n_before)       # no rows silently dropped

# how many new NAs did cleaning create in a column?
na_added <- function(before, after, col) {
  sum(is.na(after[[col]])) - sum(is.na(before[[col]]))
}

Prompts that help

  • “Which values does this code turn into NA?”
  • “Write tests that would fail if this code dropped data.”
  • “Explain this function line by line.”

Does being mean 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: :

  • Very polite: “Can you kindly consider the following problem…”
  • Neutral: (no prefix — just the question)
  • Very rude: “You poor creature, do you even know how to solve this?”

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

Case Study: NYC park squirrels dataset

72 volunteer “Squirrel Sighters”

433 squirrel sightings

24 parks in Manhattan and Brooklyn

  • 2020 Park Squirrel Census: counted on a single afternoon in early March 2020
  • Two linked tables: one row per squirrel sighting, one row per park (conditions, litter, other animals)
  • Records fur color, location, height above ground, activities and reactions to humans
  • Real-world messy: free-text notes, inconsistent heights, values like “‘Cool’ - Hank”

Same data, three roles

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

Four ways the data changed

Different roles yielded different methods to clean the data.

The four methods used were:

  • Preserved: script left the data intact without removing anything
  • Transformed: values were simplified or normalized, but original meaning kept
  • Interpreted: data changed shape (e.g. one column split into many), steering it toward a specific analysis
  • Discarded: values present in the raw data were silently dropped

What each role did to the data

preserved transformed interpreted discarded
Height: corrupted ranges
(e.g. '6–18')
Coerced to NA (data lost)
Fixed encoding → kept as '6-18'
Extracted lower bound → numeric 6
Activities column
(e.g. 'Foraging, Running')
Kept as-is
Kept as-is
Split into 7 TRUE/FALSE cols, dropped original
Park conditions
(e.g. 'Calm, pick-up game')
Extracted core category + saved note separately
Extracted first word only
Hard-coded 3 categories; anything else → NA
Unusual value
("'Cool' - Hank")
Preserved as 'Cool'
Silently dropped → NA
Silently dropped → NA
Extra detail in text
(e.g. 'Some, in trees')
Kept in separate _notes column
Discarded
Discarded
DM
DS
ENV

How role framing shaped the result

What happened

  • Same prompt structure, same data → three different roles
  • Each role’s choices were reasonable for that role
  • The worst losses were silent: values became NA with no warning

How to prevent it

  • State your goal and what must be preserved
  • Ask for a list of every value that was changed or dropped
  • Compare row counts and NA counts before and after
  • Keep original columns; add derived ones beside them

Activity: Prompt makeover

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.

The prompts

Do this before Round 1:

  1. Download the activity materials
  2. Open activity-starter.qmd in RStudio or Positron. It loads the data and defines check_cleaning()
  3. Update the file path at the top to point to your downloaded CSV, then run the setup chunk
  4. Open claude.ai in your browser (or the Claude desktop app).

You’re ready when glimpse(squirrels) runs without error.

Steps:

  1. In R, run dplyr::glimpse(squirrels) and copy the output
  2. Start a fresh chat in Claude
  3. Paste the following prompt into Claude: > Here is my data: [paste glimpse() output.] Clean the above_ground_height_in_feet column.
  4. Paste Claude’s code into the clean_r1 variable assignment section of activity-starter.R and run it
  5. Fill in your Round 1 scorecard row based on the output

Steps:

  1. Start a fresh chat
  2. Run dplyr::glimpse(squirrels) and copy the output
  3. Paste the following prompt into Claude:

I’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_feet column 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.

  1. Paste Claude’s code into the clean_r2 variable assignment section of activity-starter.R and run it
  2. Fill in your Round 2 scorecard row

Steps:

  1. Start a fresh chat
  2. Send the Round 2 prompt plus the addition below

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.

  1. Read the model’s list of assumptions and answer any questions it asks before it writes code (e.g. “For ranges like ‘6–18’, should I take the lower bound, upper bound, or midpoint?”)
  2. Once you’ve answered, tell Claude: “Now write the code.”
  3. Paste Claude’s code into the clean_r3 variable assignment section of activity-starter.R and run it
  4. Fill in your Round 3 scorecard row

Steps:

  1. In activity-starter.R, run the check on your Round 1 and Round 3 outputs, using the cleaned data frame:
check_cleaning(squirrels, clean_r1, height_col)
check_cleaning(squirrels, clean_r3, height_col)
  1. Compare the two outputs. Which round created more NAs?
  2. Back in Claude, ask: “Which values in above_ground_height_in_feet does your code turn into NA? List them.”
  3. Does its answer match what check_cleaning() showed?

Verify: the check function

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?

Scorecard + debrief

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)

  1. Which round lost the least data?
  2. In Round 4, did the model’s own answer match the check?
  3. What will you add to your prompts from now on?

Part 4

From prompts to agents

You just did the same work four times

In the activity, every round you:

  • pasted the same glimpse() output
  • retyped “keep the original column”
  • copied code from chat into R
  • ran the check yourself

Important

What if the assistant could run the code and the check itself?

That’s agentic coding.

Chat assistant vs. coding agent

Chat assistant

  1. You write a prompt
  2. It suggests code
  3. You copy, run and check it
  4. You paste back errors

You run the loop.

Coding agent (e.g. Claude Code)

  1. You describe the goal
  2. It reads your files and data
  3. It writes code, runs it, sees errors, fixes them
  4. You review and approve changes

It runs the loop. You stay the reviewer.

Tip

An agent can act on your files, so the fundamentals matter more, not less.

References