Cloud Tech by Victor
BackendIntermediate

Prompt Engineering

Why a role set in the system prompt shapes every response differently than the same instruction in a user message, and why 3-5 well-chosen examples reliably steer output format better than more instructions alone.

Updated 2026-07-243 min read

Overview

A system prompt sets standing role and behavioral context for an entire conversation, even a single sentence measurably shapes tone and focus, in a way the same instruction repeated in a user message doesn't, because the model treats system-level framing as persistent context rather than part of the back-and-forth exchange. Beyond role-setting, the single most reliable lever for output format, tone, and structure is few-shot (multishot) prompting: official guidance specifically recommends 3-5 examples that are relevant to the real use case, diverse enough to avoid teaching an accidental incidental pattern, and clearly structured, typically with tags, so the model can distinguish example content from instructions. For genuinely complex prompts mixing instructions, context, examples, and variable input in one block, wrapping each kind of content in its own consistently-named tag removes the ambiguity of inferring those boundaries from phrasing alone.

Quick Reference

TechniqueWhat it doesGuidance
System promptSets persistent role/behavior for the whole conversationEven one clear sentence measurably changes output
Few-shot / multishot examplesSteers output format, tone, structure3-5 examples: relevant, diverse, structured
XML-style taggingMarks where instructions/context/examples/input begin and endUse consistent, descriptive tag names

Syntax

json
{
  "model": "claude-sonnet-5",
  "system": "You are a helpful coding assistant specializing in Python.",
  "messages": [{ "role": "user", "content": "How do I sort a list of dictionaries by key?" }]
}

Examples

xml
<!-- Structuring a prompt with tags removes ambiguity about where
     instructions end and the actual input to process begins. -->
<instructions>
Classify the ticket below as bug, feature, or question.
</instructions>

<examples>
<example><input>App crashes on login</input><output>bug</output></example>
<example><input>Add dark mode</input><output>feature</output></example>
<example><input>How do I reset my password?</input><output>question</output></example>
</examples>

<input>{{ticket_text}}</input>

Diversity in examples matters as much as relevance

Three near-identical examples can teach the model an accidental, unintended pattern (formatting quirk, incidental phrasing) instead of the actual rule you meant to demonstrate. Vary the examples enough to cover real edge cases, not just the happy path.

Visual Diagram

Common Mistakes

  • Repeating role/behavior instructions in every user message instead of setting them once in the system prompt.
  • Using only one example, or several nearly identical ones, and inadvertently teaching an incidental pattern rather than the intended rule.
  • Mixing instructions, context, and input in one undifferentiated block of text on a complex prompt, forcing the model to infer boundaries from phrasing alone.
  • Adding more and more instructions to fix an output-format problem that a few well-chosen examples would solve more reliably.

Performance

  • Every example and every tag adds real tokens to the request, counting against the context window and cost; 3-5 well-chosen examples is a deliberate balance point, not an arbitrary minimum.
  • A well-structured, tagged prompt reduces the model's own effort spent inferring intent, which in practice shows up as more consistent output, not primarily as latency.

Best Practices

  • Set role and standing behavioral context in the system prompt, not repeated per turn in user messages.
  • Choose 3-5 examples that are relevant to the real use case and diverse enough to cover edge cases, not just near-duplicates of the happy path.
  • Wrap distinct kinds of prompt content, instructions, context, examples, input, in their own consistently-named tags once a prompt grows complex.
  • Reach for better examples before reaching for more instructions when output format or consistency is the actual problem.

Interview questions

What does putting an instruction in the system prompt actually change versus putting the same instruction in the first user message?

A system prompt sets standing context and role for the entire conversation, "you are a helpful coding assistant specializing in Python," and that framing persists and shapes tone and behavior across every subsequent turn without needing to be repeated. The same sentence placed in a user message is treated as part of the conversational exchange itself, mixed in with whatever else that turn asks for, rather than as a persistent behavioral frame the model treats as instruction-level context throughout the session. Even a single well-chosen sentence in the system prompt measurably changes tone and focus, which is why role-setting belongs there rather than being re-stated per turn.

Why does official prompting guidance recommend 3-5 examples specifically, and what makes an example actually useful versus counterproductive?

Few-shot (multishot) examples are one of the most reliable levers for steering output format, tone, and structure, and guidance specifically recommends 3-5 well-chosen examples for best results, few enough to stay practical, enough to establish a real pattern rather than one potentially misleading instance. What makes an example useful is being relevant (mirroring the actual use case closely), diverse (covering edge cases so the model doesn't latch onto an incidental, unintended pattern from too-similar examples), and structured (wrapped in clear tags so the model can distinguish example content from the surrounding instructions). A single example, or several near-duplicate ones, risks teaching an accidental pattern instead of the intended one.

What problem does wrapping different parts of a prompt in XML-style tags actually solve?

A complex prompt often mixes several genuinely different kinds of content in one block of text, instructions, background context, few-shot examples, and the actual variable input to process, and a model has to infer where one ends and the next begins from phrasing alone if nothing marks the boundaries. Wrapping each kind of content in its own consistently-named tag, `<instructions>`, `<context>`, `<example>`, `<input>`, removes that inference step entirely: the structure itself tells the model unambiguously what role each piece of text plays, which reduces misinterpretation especially as a prompt grows longer or nests multiple documents or examples.

References

ShareXLinkedInReddit
Was this page helpful?
Suggest an improvement