quiet robot

Recipe: Improve a prompt until it passes

Runs a prompt on a fixed eval set, and while it misses, has Claude rewrite the prompt from the mistakes and runs it again. What it does, when to use it, how to make it yours, and what a run costs.

View as Markdown

Runs a prompt on a fixed eval set and checks every answer. While it misses, Claude rewrites the prompt from the mistakes and the eval runs again, up to the loop limit. The prompt that passes is saved.

At a glanceNotes
LevelAdvanced
CategoryEvals
ShapeRun the eval, Decide, rewrite the prompt, retry
PlanFree and up
Needs a Claude keyYes
Limits it comes with3 loops, 600 seconds, $0.20
Improve a prompt until it passes, as it is on the canvas.Load the eval and prompt (Run command), Run the prompt (Ask AI), All right? (Decide), Rewrite the prompt (Ask AI), Save the prompt (Run command). Arrows: Load the eval and prompt to Run the prompt; Run the prompt to All right? on Either way; All right? to Rewrite the prompt on No; Rewrite the prompt to Run the prompt; All right? to Save the prompt on Yes.Either wayNoYes>_ RUN COMMANDLoad the eval and prompt✦ ASK AIRun the prompt◆ DECIDEAll right?✦ ASK AIRewrite the prompt>_ RUN COMMANDSave the prompt
Improve a prompt until it passes, as it is on the canvas.
Try it nowSimulateRun

Opens it in the Playground as a flow of your own. Simulate shows what a run costs. Run asks before it starts.

The steps

StepBlockWhat it does
Load the eval and promptRun commandSaves eight support tickets with known labels, and a first prompt that doesn't say which labels to use.
Run the promptAsk AI, JSONRuns the prompt on the tickets with Claude Haiku, as JSON.
All right?DecideScores the answers and lists each wrong one. Yes when all are right.
Rewrite the promptAsk AI, TextClaude (Sonnet) rewrites the prompt from the mistakes, without copying the eval's tickets into it.
Save the promptRun commandSaves the prompt that passed.

When to use it

  • A prompt works most of the time, and you want it to work on every case you know.
  • You want each change to a prompt checked against the same cases.
  • A cheap model should do the job, with a stronger one improving its prompt.

Run it

The quick way: choose Try it now under the drawing. It opens the recipe in the Playground as a flow of your own, after you sign in if you aren't yet. Simulate opens it and shows the forecast, and Run opens it and asks before it starts, with what the run will likely cost. From the dashboard instead:

  1. In the dashboard sidebar, open Agent Playground → Recipes and find Improve a prompt until it passes. Choose Advanced to filter the list. In the builder, Recipes in the toolbar lists them too.
  2. Choose Use this recipe. It becomes a flow of your own, so changing it never changes the recipe.
  3. If you haven't yet, save your Claude key on the Secrets page. The builder offers Add a key… in the step's key list if it's missing.
  4. Choose Simulate to see the forecast, then Run.

What you'll see: The first prompt gets about 5 of 8 right: it answers "question" where you wanted "how-to". Claude rewrites it, the eval runs again, and the second prompt usually passes. Open Rewrite the prompt to read each version.

Make it yours

  1. Put your own cases in evals/questions.md and evals/answers.json, and your prompt in evals/prompt.txt.
  2. Change the scoring in evals/score.py, for example allow one miss, or check a JSON field.
  3. Keep a separate held-out set and score the saved prompt on it, so the prompt isn't just fitted to these cases.

What a run costs

These are the builder's own forecast for the recipe as it comes, with its limits, rounded. Simulate shows the same numbers for your version, and they change as you change the flow.

NotesTypical1 in 10 runsAt most
Sandbox time$0.0002$0.0005$0.007
Claude, on your key$0.003$0.010the run's spend limit
How long it takes19 seconds37 seconds600 seconds

A typical run uses $0.00024 of sandbox time, so about 4,200 runs cost $1, and every plan includes $5 of usage a month. Claude is billed by Anthropic to your own key, at their usual prices. The run counts it toward its spend limit, so it can't overspend, but we don't charge you for it. At most is the most a run could cost with these limits: it stops at $0.20 or 600 seconds, whichever comes first.

  • Agent PlaygroundQuickstart: build and run your first flow
  • Agent PlaygroundBlocks
  • Agent PlaygroundRecipes
  • SandboxesQuickstart: your first sandbox
  • SandboxesMCP server
  • SandboxesAPI reference
  • InsightsAll posts