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.
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 glance | Notes |
|---|---|
| Level | Advanced |
| Category | Evals |
| Shape | Run the eval, Decide, rewrite the prompt, retry |
| Plan | Free and up |
| Needs a Claude key | Yes |
| Limits it comes with | 3 loops, 600 seconds, $0.20 |
Opens it in the Playground as a flow of your own. Simulate shows what a run costs. Run asks before it starts.
The steps
| Step | Block | What it does |
|---|---|---|
| Load the eval and prompt | Run command | Saves eight support tickets with known labels, and a first prompt that doesn't say which labels to use. |
| Run the prompt | Ask AI, JSON | Runs the prompt on the tickets with Claude Haiku, as JSON. |
| All right? | Decide | Scores the answers and lists each wrong one. Yes when all are right. |
| Rewrite the prompt | Ask AI, Text | Claude (Sonnet) rewrites the prompt from the mistakes, without copying the eval's tickets into it. |
| Save the prompt | Run command | Saves 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:
- 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.
- Choose Use this recipe. It becomes a flow of your own, so changing it never changes the recipe.
- 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.
- 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
- Put your own cases in
evals/questions.mdandevals/answers.json, and your prompt inevals/prompt.txt. - Change the scoring in
evals/score.py, for example allow one miss, or check a JSON field. - 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.
| Notes | Typical | 1 in 10 runs | At most |
|---|---|---|---|
| Sandbox time | $0.0002 | $0.0005 | $0.007 |
| Claude, on your key | $0.003 | $0.010 | the run's spend limit |
| How long it takes | 19 seconds | 37 seconds | 600 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.