
The Patterns Worth Stealing From the Claude Cookbooks
Runnable notebooks beat prose about prompting. The four patterns in there that changed how I build features on top of a model.
There is a lot of writing about prompting and most of it is unfalsifiable. The cookbooks are the opposite: notebooks you run, with inputs and outputs you can change. Four patterns from them ended up in production work of mine.
1. Tool use is the real API
The moment a model can call your functions, the shape of the feature changes. It stops being "generate text about the data" and becomes "decide which of my functions to call, with what arguments".
tools = [{
"name": "search_projects",
"description": "Search the project catalogue by keyword and year.",
"input_schema": {
"type": "object",
"properties": {
"query": {"type": "string"},
"year": {"type": "integer"}
},
"required": ["query"]
}
}]
Your code executes the call and returns the result; the model never touches the database. That boundary is also the security boundary — validate arguments exactly as you would validate a request from the internet, because that is what it is.
The description field does more work than the schema. Vague descriptions produce tools called at the wrong time.
2. Prefill the response
Constrain the output shape by starting the assistant's turn yourself:
messages = [
{"role": "user", "content": prompt},
{"role": "assistant", "content": "{"},
]
Now it continues JSON rather than opening with a sentence about what it is going to do. This removes an entire category of brittle output parsing, and it works better than asking politely for JSON in the instructions.
3. Chain small calls instead of one large one
A single prompt doing extraction, judgement and formatting is hard to debug because you cannot see which stage failed. Split it: extract to structured data, then evaluate, then format. Each step is inspectable, cacheable, and individually replaceable.
It costs more tokens and it is worth it, because the alternative is a black box that occasionally produces something wrong and gives you no way to find out where.
4. Build the eval before you tune the prompt
Twenty labelled examples and a script that scores them. Without it, prompt iteration is vibes — you change wording, it looks better on the two inputs you tried, and you have no idea what regressed.
This is the pattern people skip and the one that matters most. Every other improvement is unmeasurable without it.
The framing that stuck
Treat the model as a component with a contract, not as a magic layer. It has inputs you control, outputs you validate, failure modes you handle, and a cost you measure. Everything above follows from taking that seriously.
Resources
- Repo: anthropics/claude-cookbooks
- Docs: docs.claude.com
- Video walkthroughs: YouTube: claude api tool use tutorial
- Related: Claude Code: when the agent has a terminal
Need this built properly?
I build secure, fast, bilingual platforms for clients across Egypt, Saudi Arabia, the UAE and Kuwait.


