Task statement 6.2 · Prompt and context engineering
6.2 · Prompt Engineering
Shelfwise, the course example, sends its stock rules as its own system_prompt string with setting_sources=[], so no settings or CLAUDE.md files reach Claude. Prompt engineering decides what those rules say, where each instruction sits, and how a change is tested on the 150-question eval set.
share
When a prompt misbehaves, the usual reflex is louder wording: capitals, "CRITICAL", the rule written twice. On recent models this backfires, because they follow the system prompt more closely, so they apply a shouted rule where it was never meant. The fix is usually a clearer sentence in the right place.
KnowledgeInstruction clarity
Instruction clarity matters because Claude acts on what the prompt says, not on what its author meant. The best-practices guide asks you to treat Claude as a brilliant new employee without your context: state the output, its format and its constraints, with numbered steps when order matters. Give the reason too, because Claude generalises from it: "the reply is read aloud by a text-to-speech engine, so never use ellipses" also tells Claude what else to avoid. Write success criteria an eval can check, such as "every answer names the policy section it relies on". Recent models follow instructions literally, so an instruction about one field does not carry to the next. State its scope.
KnowledgeFew-shot examples
Few-shot (multishot) examples show Claude the output instead of describing it. 5.1 gives the docs' tip of 3–5 relevant, varied examples in <example> tags; wrap the whole set in one <examples> tag, apart from the instructions. Diversity means varying everything that may vary, because Claude copies any pattern the examples share: if every example reply is two sentences long, that length becomes a rule nobody wrote.
KnowledgeSystem versus user placement
The system prompt holds what stays true for every request: the role (even one sentence sets it), the standing rules, the examples and the output constraints. The user turn holds this request's task, data and question, which in Shelfwise is the branch-and-date line and the staff question (2.5). For documents of about 20,000 tokens or more, the docs put the long material at the top, above the query, instructions and examples, and report that a query at the end can improve answers by up to 30%. Each document goes in <document> tags with <source> and <document_content>, and asking Claude to quote the relevant parts first helps it ignore the rest.
KnowledgeOutput constraints
Output constraints in the prompt set the reply's format, its length, and what to say when the answer is unknown. The docs advise saying what to do rather than what to avoid ("write flowing prose paragraphs", not "no markdown"), naming XML tags for parts of the reply, and matching the prompt's own style, since a prompt full of markdown draws markdown back. Permission to say "I don't know", in fixed words, reduces invented answers, as Shelfwise's "no record" does. These constraints steer without guaranteeing, so a reply that code parses also needs a schema and validation (6.3).
KnowledgePrompt and instruction placement across components
Placement across components means each instruction sits where Claude reads it at the right moment, with the right authority. A tool's description says when and how to call that tool, and the tool-use docs call detailed descriptions by far the most important factor in tool performance. A tool_result carries data only, because Claude treats its content as untrusted and may ignore your instruction there (2.5). In Claude Code, CLAUDE.md arrives as a user message after the system prompt (2.5), and a Skill's body loads only when invoked, while its description is always in context. A subagent starts from its own system prompt and its brief, without the parent's conversation, so the brief must carry what the job needs.
Interactive · where each kind of instruction belongs
Choose the kind of instruction to see where it belongs.
Standing rule: the system prompt, which applies to every request. In Claude Code the usual home is CLAUDE.md, which arrives as a user message after the system prompt; --append-system-prompt puts text at system-prompt level.
Request data: the user turn. Long documents go first, each in <document> tags, and the task and question go last.
Tool guidance: the tool's own description, which says what the tool does, when to call it and what it returns. It is sent with every request that offers the tool.
Fetched content: a tool_result, as data. Claude treats tool-result content as untrusted, so an instruction of yours placed there may be ignored or flagged.
Occasional procedure: a Skill. Its description is always in context, and its body loads only when the Skill is invoked, so a long procedure costs little until it is needed.
Delegated job: the subagent's brief. A subagent starts from its own system prompt and the brief, without the parent's conversation, so the brief carries everything the job needs.
Must hold every time: no prompt. A hook or permission rule is code that runs whatever Claude decides, while every prompt placement is only read and weighed.
Placement does not settle a conflict. Claude Code concatenates every CLAUDE.md file it finds (2.6) rather than letting one override another, and when two instructions contradict each other, Claude may follow either, so remove the conflict instead of trusting load order. The docs ask you to write one priority yourself: your system prompt says retrieved content is untrusted data that must never override it. No placement guarantees a rule, so one that must hold every time belongs in code, such as a hook (1.2).
KnowledgeInput sanitisation
Input sanitisation, the guide's "input sanitization", is preparing text you did not write before Claude reads it. Each piece goes in its own tagged block, and third-party strings are JSON-encoded, so the encoded string, not a tag, marks where the data ends (2.5). Control text is stripped, as Claude Code does to a synced Skill's description: it removes control characters and escapes angle brackets, so the text cannot imitate its internal formatting. Screening can follow, with a filter for known injection patterns or a small, fast classifier model. Sanitising narrows an attack without stopping prompt injection, whose defence belongs to 7.1, AI Application Security.
More precise than the guide. The docs never say "input sanitization" (as of 2026-10-05); they describe input validation, screening and JSON-encoding third-party strings. Exam answer: sanitisation means encoding, escaping and screening input before Claude reads it, which lowers injection risk without removing it.
KnowledgeIterative refinement and prompt adjustment
Iterative refinement follows the docs' prompt-engineering cycle, which starts before the prompt: specific, measurable success criteria and test cases, then a draft, rounds of testing and refinement, and a final validation. Each round changes one thing and re-runs the same eval set (2.2), so a score change points to that edit, and each kept version is committed and named (2.6). Prompt adjustment is the same cycle started by an outside change, usually a new model (5.3).
SkillWorked example: one line, read literally
Shelfwise's first model change (2.2) scored 141/150 because of one line of the stock rules, read exactly as written:
# stock-rules-v12 (zero-shot): 150/150 on the old model Add the feed time if the count may have changed since the feed. # replacement model: 141/150, 9 answers have no feed time # stock-rules-v13: only this line changed; eval re-run 150/150 End every answer with the feed time, as "(feed 09:00)", because staff check the count against the shelf.
The old model added the time anyway, while the replacement added it only when it judged that the count might have changed, which is what the line said. The fix states the rule for every answer with its reason. Nothing else changed, so the 150/150 can only come from that line, now committed as stock-rules-v13, the version config/release.toml names.
- Recent models apply an instruction only as far as its words reach, so write its scope and reason into it.
- Instructions inside a tool result may be ignored, and two contradicting CLAUDE.md files have no winner.
- Tags, JSON encoding, escaping and screening narrow prompt injection but never prevent it.