How do you revise a prompt when regression evals expose a gap?
Find what the prompt left unclear. Make the instruction specific and give its reason. Say what to do rather than what not to do. Add 3–5 diverse examples, keep instructions in the system prompt with untrusted input in tagged user content, and put long documents before the question. Then add the failing cases to the regression set so the gap stays closed.
How do you protect downstream code from model output?
Use structured outputs where possible, through output_config.format or strict tool use. Still check stop_reason, since a refusal or a max_tokens cut-off can break the schema, and compare enum values case-insensitively. Keep unsupported constraints such as ranges out of the schema and validate them in code. On free-text paths, validate the parsed object and handle failures without crashing.
How do you ground answers in supplied documents and cite them?
Send documents with citations enabled on all of them, or return RAG results as search_result blocks, and Claude cites the spans it used. Allow "not found" when the answer isn't there. Choose full context for small, stable corpora, and retrieval for large or fast-changing ones. Remember that citations can't be combined with structured outputs.
How do you keep a long-running session or agent on track?
Watch for drift: forgotten constraints and repeated work. Clear old tool results with context editing, compact with instructions on what to keep, move noisy exploration into subagents, keep a progress note outside the context, and start a fresh session for an unrelated task.