System Prompt Structure
A well-structured system prompt contains: role definition, behavioral constraints, output format specification, and context. Order matters — Claude weighs earlier content more heavily.
| Section | Purpose | Example |
|---|
| Role | Define persona and expertise | You are a senior code reviewer... |
| Constraints | Set boundaries | Never execute code. Only analyze. |
| Output Format | Define structure | Respond in JSON with fields: severity, message, line |
| Context | Provide background | The codebase uses TypeScript and React... |
Structured Output Techniques
| Technique | Reliability | When to Use |
|---|
| Tool use (forced) | Highest | Production systems requiring exact schema |
| Prefilling ({) | High | Simple JSON when tool use is unavailable |
| System prompt instructions | Medium | Flexible formatting, non-critical outputs |
| XML tags | Medium-High | Multi-section responses with clear boundaries |
Key rule: For production JSON output, use tool use with a defined schema. It is the only method that guarantees schema compliance.
Prompt Chaining Decisions
Chain when: steps need different models, temperatures, or tools. Steps have independently verifiable outputs. You need to inspect or modify intermediate results.
Single call when: the task is straightforward, all steps need the same context, and latency matters.
| Anti-Pattern | Why It Fails |
|---|
| Chaining simple tasks | Added latency and cost for no quality improvement |
| No validation between steps | Errors propagate and compound through the chain |
| Passing full context between steps | Token waste — pass only what the next step needs |
Few-Shot Example Rules
| Rule | Details |
|---|
| Include 2-5 examples | Fewer may not establish the pattern; more wastes tokens |
| Cover edge cases | Show the hard cases, not just the obvious ones |
| Consistent format | Examples must match the expected output format exactly |
| Place after instructions | Instructions first, then examples, then the real input |
| Use diverse examples | Avoid examples that are too similar to each other |
Key Parameters
| Parameter | Default | When to Change |
|---|
| temperature | 1.0 | 0 for deterministic output (JSON, classification) |
| max_tokens | Model dependent | Set explicitly to control output length and cost |
| top_p | Model dependent | Rarely needed — temperature is usually sufficient |
| stop_sequences | None | Custom stop tokens for structured output parsing |