Core Techniques
Prompts are code — versioned, tested, engineered. Six techniques that separate 'it sometimes works' from 'it ships.'
▶ Watch this reelWhat you'll learn
- Clear instructions & role
- Few-shot examples
- Chain-of-thought
- XML / delimiters
- Output format control
- Negative instructions
Remember this
- Role + task (verbs) + format + constraints — specificity is the #1 quality lever
- Few-shot examples beat descriptions; chain-of-thought for multi-step problems
- Tag data with XML; spec outputs field-by-field; phrase constraints as positive behavior
Clear instructions & role
- Structure: role → task (verbs) → format → constraints.
- Vague prompts leave degrees of freedom that become surprises.
Few-shot
- 2–5 input→output examples teach tone, format, boundaries.
- Order simple → tricky; keep examples perfectly consistent.
- Almost-right output? Add the almost-wrong case done correctly.
Chain-of-thought
- 'Think step by step' / scaffolded steps for multi-step problems.
- Costs tokens + latency; reasoning can still be wrong → verify finals.
XML / delimiters
- Wrap external content:
<document>,<transcript>,<user_input untrusted="true">. - Semantic tag names steer attention; tagged data blurs less into instructions.
Output format control
- Field-by-field specs · length in real units (words/items, not 'be concise').
- Feeding a machine? Use structured output schema (GA-04) to enforce.
Negative instructions
- 'Don't X' mentions X. Pair prohibitions with positive, concrete replacements — placed last.
Code: A production-grade prompt template
PROMPT = """You are a senior support triage engineer.
Classify each ticket by urgency.
<rules>
- P1: money lost or service down
- P2: degraded but usable
- P3: feature requests and questions
</rules>
<examples>
Q: app crashes on login
A: {"urgency": "P1", "reason": "service unusable"}
Q: report export is slow
A: {"urgency": "P2", "reason": "degraded, workaround exists"}
</examples>
Answer with JSON only: {"urgency": "...", "reason": "one sentence"}.
Reason in at most 2 short steps, then the JSON.
<ticket untrusted="true">
{ticket}
</ticket>
"""
# Usage — THIS is a prompt template (GA-06 versions it):
ticket = "charged twice for one order"
messages = [{"role": "system", "content": PROMPT.replace("{ticket}", ticket)}]