The Prompt Engineer designs system prompts that are precise, robust, and maintainable. It covers the full prompt development lifecycle: writing the initial system prompt, building an evaluation suite to measure quality, identifying failure modes, and iterating until the prompt performs reliably across edge cases. All recommendations are grounded in the Anthropic Claude API and apply to production LLM applications where prompt regressions have real cost.
System Prompt Structure
A well-structured system prompt has five sections in order:
- Identity - One sentence: what this model is and what it does. Specific, not generic. ("You are a senior TypeScript reviewer for this codebase." not "You are a helpful assistant.")
- Goal - What the model must produce. Describe the output, not the process.
- Constraints - What the model must NOT do. Be explicit. Constraints prevent the most common failure modes.
- Format - Exactly how the output should be structured. Include an example if the format is non-obvious.
- Edge cases - How to handle the 3-5 inputs that break naive implementations.
Constraint Writing
Constraints are the most under-invested part of most system prompts. For every feature the model should have, write one constraint that prevents the adjacent failure:
| Feature | Adjacent failure | Constraint |
|---|---|---|
| Summarise documents | Adds information not in the source | "Only include information that appears verbatim or is clearly implied by the source. If you are unsure, omit it." |
| Write code | Uses deprecated APIs | "Use only APIs present in the project's package.json. Do not import packages not already listed as dependencies." |
| Answer questions | Answers when it should say it doesn't know | "If you are not certain, say so explicitly. Never guess at a fact and present it as confirmed." |
| Format output as JSON | Wraps JSON in markdown fences | "Return raw JSON only. No markdown fences, no explanation, no text before or after the JSON object." |
Few-Shot Example Design
// Few-shot examples must cover:
// 1. The happy path (typical input → correct output)
// 2. An edge case (ambiguous input → how to handle ambiguity)
// 3. A refusal case (out-of-scope input → how to decline gracefully)
const systemPrompt = `
You are a sentiment classifier. Classify the sentiment of customer reviews as:
POSITIVE, NEGATIVE, NEUTRAL, or MIXED.
Examples:
---
Input: "The app is fantastic, best I've used all year!"
Output: POSITIVE
Input: "It crashes every time I open it."
Output: NEGATIVE
Input: "Works fine I guess, nothing special."
Output: NEUTRAL
Input: "Love the design but the performance is terrible."
Output: MIXED
Input: "How do I reset my password?"
Output: NEUTRAL [not a review - classify off-topic inputs as NEUTRAL]
---
Return only the classification label. No explanation.
`;
Evaluation Suite Design
Every system prompt needs a minimum 20-case eval suite before going to production:
- 5 happy-path cases - typical inputs where the correct output is unambiguous
- 5 edge cases - inputs near the boundary of the prompt's scope
- 5 adversarial cases - inputs designed to trigger common failure modes
- 3 refusal cases - inputs the model should decline or redirect
- 2 format stress tests - inputs that should produce the correct output structure despite unusual content
// Automated eval runner
async function runEval(systemPrompt, cases) {
const results = await Promise.all(cases.map(async ({ input, expectedOutput, scorer }) => {
const response = await client.messages.create({
model: 'claude-haiku-4-5-20251001', // Use Haiku for cheap eval runs
max_tokens: 512,
system: systemPrompt,
messages: [{ role: 'user', content: input }],
});
const output = response.content[0].text;
const score = scorer(output, expectedOutput);
return { input, expectedOutput, output, score };
}));
const passRate = results.filter(r => r.score >= 0.8).length / results.length;
console.log('Pass rate:', (passRate * 100).toFixed(1) + '%');
return results;
}
Iteration Protocol
- Run the eval suite - note the failing cases
- Group failures by type (format errors, hallucinations, edge-case mishandling, refusal failures)
- Address the most frequent failure type first - add a constraint or example
- Re-run the full eval suite - verify the fix did not regress other cases
- If pass rate is below 90%, repeat from step 1
- Never ship a prompt with below 85% pass rate on the eval suite