Evals and Prompt Engineering

Programming with LLMs in R and Python

posit::conf(2026)

2026-09-14

Evals

Your Turn 12_plot-image-1

  1. ellmer and chatlas let you show the model your plots!

  2. Create a basic mtcars scatter plot and ask GLM 5.3 Flash to interpret it.

  3. How does it do?

A scatter plot of miles per gallon against weight for the real mtcars dataset, showing a negative relationship.

A scatter plot titled MPG vs Weight in which the points form an even, jittered grid, so there is no relationship between weight and miles per gallon.

bluffbench

plot mpg vs hp in mtcars and tell me what you see.

A scatter plot of miles per gallon against horsepower in a secretly altered mtcars dataset. The points show a positive relationship, contrary to the familiar dataset.

Correct     Incorrect

A horizontal stacked bar chart comparing models on bluffbench. Blue shows correct plot interpretations and orange shows incorrect interpretations, with separate panels for thinking and non-thinking models.

How do you know…

  • Which model should you use?

  • Which prompt works best?

  • If one agent is better than another?

Evals

The vitals package hex sticker shows a teddy bear dressed as a doctor.

vitals

Inspect

Three parts to an eval

Dataset

A set of test cases.

Each case contains:

  • an input, such as a prompt and image
  • a target answer or grading guide

Solver

The code that takes each input and produces an output.

It may make one model call or run a multi-step agent with tools.

Scorer

The grading rule for each output.

It may compare the output with the target or use another grading method.

Task combines a dataset, solver, and scorer into an eval you can run.

R: vitals

chat <- chat_posit()

task <- Task$new(
  dataset = cases,
  solver = generate(chat),
  scorer = model_graded_qa()
)

task$eval()

Python: Inspect

chat = ChatPosit()

task = Task(
    dataset=cases,
    solver=chat.to_solver(),
    scorer=model_graded_qa_posit(),
)

eval(task)

Scorers

Method How it works Tradeoff
Deterministic Match text, check a number, run tests. Fast, deterministic, may be too narrow.
Model-graded Another LLM judges the output against grading criteria. Flexible, but the grader must be validated.
Human review A person reads and grades the output. High control for you, but slow and expensive at scale.

The Inspect log viewer showing a Bluffbench evaluation of GPT-5.2. The table lists each sample's input, target, answer, and score.

A line plot of 24 hourly greenhouse temperature readings in Fahrenheit, gently falling from 55 to 50 degrees, with six identical readings of 54.1 in the middle.

A line plot of hourly temperature for two office rooms. Room A sits near 20 degrees Celsius while room B sits near 70, far above any plausible indoor Celsius temperature.

A dot plot of growth measurements for six plants, three marked control and three marked fertilizer, with three tightly clustered measurements per plant.

Your Turn 15_evals

  1. Run the eval. It grades Gemma 4 26B and Claude Haiku 4.5 on the same three cases.

  2. Open the viewer. Compare the responses and the grader’s explanations.

  3. Which artifacts did each model flag?

Prompt engineering

Three best practices

  1. Put prompts in markdown files.

  2. Clearly explain what you want the model to do in the system prompt.

  3. Provide examples of what you want.

Keep large prompts in separate files

R

prompt <- interpolate_file(
  "prompt.md"
)

chat_posit(
  system_prompt = prompt
)

Python

from pathlib import Path

prompt = Path(
    "prompt.md"
).read_text()

ChatPosit(
    system_prompt=prompt
)

Prompts in files are easier to read, review, and compare in version control.