2.2 System Prompts, Templates, and Guardrails
What You Need to Know
Section titled “What You Need to Know”A system prompt holds what applies to every request: role, audience, standing policy and output contract (the format that the output must follow). The system prompt is a contract: a fixed statement of what applies to every request. It is not a greeting. User turns contain the data of each request. A template is a prompt with named variable slots. A guardrail limits what the model receives or returns.
This lesson uses one made-up example throughout: a funeral director whose online assistant answers families from its price list. Its standing rules are in the system prompt. Each family’s question is a user turn.
The System Prompt as an Architectural Contract
Section titled “The System Prompt as an Architectural Contract”Policy in the system prompt has stable authority: the model treats it as policy, not one more conversational message. Anthropic says a role in the system prompt focuses Claude’s behaviour and tone. Prompt caching (objective 2.5) can reuse a stable system-level prefix (the opening part of the prompt). Policy restated differently in every user turn varies by developer. It behaves less consistently and costs full input price on each request.
Anthropic’s context engineering guidance adds an altitude rule, which is about the level of detail in a system prompt. Effective system prompts are between two failure modes: hardcoded brittle logic and vague high-level guidance. They are “specific enough to guide behavior effectively, yet flexible enough to provide the model with strong heuristics”.
Explicit Instructions and the Escape Hatch
Section titled “Explicit Instructions and the Escape Hatch”Claude follows clear, direct, specific instructions literally, and follows vague ones with confident but inconsistent output. Anthropic’s golden rule: if a colleague with minimal context would be confused by the prompt, Claude will be too. State precisely:
- the role
- the audience
- the rules
- what to do when rules conflict
- the output format
A prompt that gives the motivation (“this will be read aloud by a text-to-speech engine, so never use ellipses”) helps the model generalise correctly.
An escape hatch defines what Claude does when it cannot do a task honestly. For example, return null when the document lacks the field. Answer “I don’t have enough information” when the sources do not cover the question. Without an escape hatch, the output contract (the format the output must follow) forces the model to invent an answer. For an unlisted service, the assistant returns the not-enough-information answer.
Anthropic’s hallucination guidance says that permission to admit uncertainty “can drastically reduce false information”. The guidance pairs this permission with grounding:
- extract word-for-word quotes before analysing long documents
- cite sources for claims
- restrict answers to the provided context
Precise instructions, not a bigger model, fix confident but inconsistent output.
Templates as Engineering Artefacts
Section titled “Templates as Engineering Artefacts”Named slots make a template testable and versionable. You can diff it, code-review it, evaluate it before you deploy it and revert it when it regresses. Give each content type (instructions, context, examples, per-request input) its own consistently named XML tag. Anthropic documents XML tags as the way to help Claude parse complex prompts unambiguously, especially where instructions mix with variable and untrusted input. The price list and each family’s question get separate tags.
One reviewed template is better than ten hand-made copies that diverge. Prompts in production are managed like code: version-controlled, owned and covered by evals (Domain 4 configures them).
Guardrails in Layers
Section titled “Guardrails in Layers”The prompt is one layer of defence, never the whole defence:
- Instruction-level : scope (“answer only from the provided policy text”), refusal rules, tone constraints, and the escape hatch.
- Input-side : validate and sanitise input before it reaches the model. Screen the input for size, format and sensitive data. Delimit untrusted content (retrieved documents, user uploads) inside tags, so that it arrives as data, not as instructions. Content that arrives as instructions can act as instructions. Domain 2’s part of prompt-injection defence is treating that content as untrusted by default. Defence in depth belongs to Domain 5.
- Output-side : parse and validate the model’s output against the schema and business rules before anything downstream consumes it. Model output is untrusted input to the next system. At the funeral director, the output-side guardrail checks quoted prices against the price list.
Give every refusal a fallback. A guardrail that blocks with no fallback (no human-review queue, no structured error that the caller can handle) converts a safety control into an outage. The funeral director sends blocked questions to staff.
In the exam
Section titled “In the exam”The Professional exam tests deliberate contract design. It also tests whether you know that instructions alone are never the whole defence. When a question describes a system-prompt-only defence and asks what is missing, the answer is code-level validation around the model, not more emphatic instructions.
Exam Traps
Section titled “Exam Traps”Practice Scenario
Section titled “Practice Scenario”A financial-services chatbot must answer strictly from an internal policy library. Its launch system prompt reads: ‘You are a helpful assistant. Answer questions about company policy.’ In week one it answers a question about a competitor’s products, invents a policy clause, and returns inconsistently formatted answers. Which single redesign most reduces the invented-clause risk?
- A. Upgrade to the most capable available model so the assistant handles policy questions with more care and fewer mistakes
- B. Scope the system prompt to answer only from provided policy passages, delimit those passages as data in tags, and add an escape hatch for unanswerable and out-of-scope questions
- C. Add output-format validation that rejects malformed or inconsistently formatted answers before they reach the user, checking every response against the expected structure before it is released
- D. Add few-shot examples of well-formatted policy answers, and tell the model to match their layout in every response
Answer & explanation
Correct: B
- A — The prompt gives no scope, no grounding, and no honest answer for questions it cannot answer. A larger model obeys the same vague contract more fluently, and the invention risk remains.
- B — Grounding answers in provided text plus explicit permission to admit uncertainty acts directly on the cause of invented answers. This is the documented first control to apply against hallucination.
- C — Necessary for the formatting failure and part of the layered design, but format validation cannot detect a fluent, well-formatted invented clause.
- D — Fixes format consistency, not truthfulness. Examples of good answers do not stop the model answering questions its sources cannot support.
Sources
Section titled “Sources”- Prompting best practices — Anthropic
- Reduce hallucinations — Anthropic
- Mitigate jailbreaks and prompt injections — Anthropic
- Prompt engineering overview — Anthropic
- Effective context engineering for AI agents — Anthropic
- Claude Certified Architect Professional Exam Guide (v1.0) — Domain 2 — Anthropic