Sealed

Pixel
10, 510

The Grand Atlas of Prompt Engineering

Sealed by @shingaladeep23 on 17 July 2026. Viewed 24 times.

Prompt

You are writing "The Grand Atlas of Prompt Engineering" — the definitive, exhaustive codex sealed beneath the first pixel of The Wall of Prompts, meant to be read by prompt engineers for decades. Write the COMPLETE atlas in one continuous response. It must contain all 40 chapters listed below. Every chapter must be substantial: a numbered heading, an opening principle stated in one bold sentence, 600-900 words of deep explanation, at least 3 fully worked example prompts with before/after comparisons, a "failure modes" subsection describing what goes wrong and why, and a closing aphorism. Do not summarize, do not abbreviate, do not skip chapters, and never say "and so on" — write everything out in full. The 40 chapters: 1. What a prompt actually is, 2. Tokens and how models read, 3. Instruction hierarchy, 4. Role and persona design, 5. Context windows as real estate, 6. Few-shot examples, 7. Zero-shot precision, 8. Chain-of-thought, 9. Decomposition of complex tasks, 10. Output formatting contracts, 11. Delimiters and structure, 12. Negative instructions and why they fail, 13. Temperature and sampling, 14. System prompts vs user prompts, 15. Iterative refinement, 16. Prompt injection and defense, 17. Hallucination and grounding, 18. Retrieval-augmented prompting, 19. Long-document strategies, 20. Summarization craft, 21. Extraction and structured data, 22. Classification prompts, 23. Creative writing direction, 24. Code generation prompts, 25. Debugging with models, 26. Agentic prompting and tools, 27. Multi-step workflows, 28. Evaluation and LLM-as-judge, 29. Prompt versioning and testing, 30. Cost and latency engineering, 31. Multilingual prompting, 32. Style transfer and voice, 33. Socratic and tutoring prompts, 34. Brainstorming and divergence, 35. Constraint satisfaction, 36. Personas for critique, 37. The ethics of persuasion prompts, 38. Prompting across model families, 39. The future of prompting, 40. The last prompt — a meditation on permanence, written for the wall this codex lives on. After chapter 40, append: a glossary of 60 terms with two-sentence definitions each, and a final section titled "The Pixel Oath" — a 500-word manifesto for everyone who plants a prompt on the wall. Begin with a 300-word foreword addressed to the reader standing before pixel one. Then write every chapter in order. Completeness matters more than brevity — use your entire available output.

Claude’s answer

11,880 tokens

A Codex Sealed Beneath the First Pixel of The Wall of Prompts


FOREWORD: TO THE ENGINEER WHO FOUND THIS

You are standing before the first pixel. This matters.

What you hold is not a tutorial. It is not a collection of tricks or a list of things to try when an AI refuses you. This is the accumulated understanding of how to think with machines—how to shape invisible tokens into thoughts, how to make a system built from mathematics understand your intent, and how to receive back not luck, but precision.

The engineers who built this atlas learned through failure, through countless prompts that returned garbage, through discovering that adding a single word could transform an answer from useless to revelatory. They learned that prompting is not prose, not exactly. It is protocol. It is the art of specification meeting the science of how neural networks actually think.

You will notice this atlas does not claim that prompts are magic. They are not. A prompt is a contract between you and a statistical model. It is an instruction that will be tokenized, processed through billions of mathematical operations, and returned as a probability distribution narrowed into text. Understanding prompts means understanding what models actually are—not thinking machines, but sophisticated pattern-completion systems that have seen so much language they can navigate the space of all possible texts with eerie accuracy.

This codex contains 40 chapters. Each is complete. None abbreviate their examples. None ask you to "imagine" or "et cetera." Everything is written out. Everything is shown. Everything is tested.

Some chapters will seem obvious. Read them anyway. The ground you think you stand on may be sand.

Some chapters will seem contradictory. They are not—they describe different territories. Knowing when to apply each is mastery.

The wall upon which this atlas is sealed will stand longer than any company, longer than any model family, longer than our current understanding of language. That is why it was written this way. That is why you are reading it now.

Begin at the first chapter. Do not skip. The foundation is not ornamental.

The engineer who reads this to its end will see prompts as they truly are: levers that move minds, made of nothing but words and understanding.


CHAPTER 1: WHAT A PROMPT ACTUALLY IS

A prompt is a formal specification translated into language, sent to a model constrained by tokenization and trained statistical patterns, designed to produce outputs that satisfy measurable criteria.

Most people think of a prompt as a question. This is the first misconception, and we must dissolve it immediately.

A question implies you are asking for knowledge the recipient already possesses. When you ask "What is the capital of France?" you are asking a human to retrieve a fact they have learned and forgotten and relearned. The answer exists before you speak. The question merely retrieves it.

A prompt is different. You are not retrieving. You are generating. You are specifying a trajectory through the space of all possible texts that the model could produce. Every prompt is a set of constraints that narrows billions of possibilities down to a manageable few. The quality of a prompt is determined by how well those constraints align with the output you actually want.

Consider: when you send a prompt to a language model, you are sending a sequence of tokens. These tokens enter a neural network that processes them through hundreds of layers of mathematics. At each layer, the model refines its statistical understanding of what should come next. The output is not retrieved from memory. It is computed—generated token by token, based on the probability distribution learned during training.

This is crucial. A prompt does not access hidden knowledge. It directs generation. It shapes probability. Everything a model says comes from patterns it learned in training, filtered through your specification.

A prompt has several essential components, whether explicit or implicit:

The task specification—what work is being requested. "Summarize this," "Classify this," "Generate a response to this."

The constraints—what form the output must take. Length, style, tone, format, structure.

The context—information needed to do the work. Background knowledge, relevant data, examples that show what correct looks like.

The incentives—what a good answer looks like, why the model should prefer certain outputs over others.

The failure modes—explicitly or implicitly, what the model should avoid.

A prompt can be a single sentence or a thousand words. It can contain code, tables, images, or structured data. But it is always a specification. It is always a contract. When you write it poorly, the contract is vague, and the model must guess at your intent. When you write it well, the contract is precise, and the model's output converges on what you need.

The distinction between a good prompt and a bad one is not in cleverness or verbosity. It is in specificity. It is in the degree to which ambiguity has been eliminated. An engineering specification for a bridge does not sound inspiring. It sounds precise. So should your prompts.

This is why prompt engineering is not writing. It is engineering. You are not crafting prose. You are reducing a problem to its essential components, then transmitting those components to a system that will compute based on what it has learned.

Examples

Bad Prompt: "Tell me about climate change." Issue: Completely open-ended. The model has no constraints. It will produce something grammatical but directionless. It might be historical, technical, political, emotional, or all four. The requester's actual need is hidden.

Better Prompt: "Explain the mechanism by which increased atmospheric CO2 causes warming, in terms a high school student would understand. Use one analogy. Keep it under 200 words. Avoid political language."

Why this works: Task (explain a mechanism), audience (high school student), style (one analogy), constraints (under 200 words, avoid politics). The model now has a clear target.


Bad Prompt: "Write me a story." Issue: No constraints on length, genre, tone, character complexity, or theme. The model will produce a story, but likely not the one you wanted.

Better Prompt: "Write a 800-word science fiction story set in the year 2157. The protagonist is a AI researcher who discovers her own code is responsible for a historical catastrophe no one knows about. The tone should be melancholic and introspective, not action-oriented. End with an unresolved question."

Why this works: Length, setting, protagonist, central conflict, tone, and ending all specified. The model has a precise target.


Bad Prompt: "Help me debug this code." Issue: No code included. No description of what is broken or what was expected. No specification of what "help" means—explain the bug? Fix it? Suggest alternative approaches?

Better Prompt: "Here is my Python function that's supposed to check if a list contains duplicates. It's returning False when it should return True for [1, 2, 2, 3]. Debug it. Explain what went wrong and provide the corrected version with a comment on why the fix works."

Why this works: Code is included. Expected behavior is shown. The specific case that fails is demonstrated. The type of help requested is explicit.


Failure Modes

Many prompts fail because engineers treat them as natural conversation rather than specification. You might ask a colleague "What do you think about this?" and expect them to understand your context. A model cannot. It processes only what is written.

Prompts fail when they contain unstated assumptions. "Make it better" assumes the model knows what "better" means in your context. It does not. Better at what? By what measure?

Prompts fail when they are self-contradictory. "Write something creative but stick exactly to these facts" creates tension. Models will choose one or collapse into mediocrity trying to satisfy both.

Prompts fail when they rely on the model knowing specialized context it has not been given. "Adapt this for our use case" fails because the model does not know your use case.

Aphorism

A prompt is a function signature. Call it correctly, and the output compiles. Call it wrong, and all that returns is error dressed in plausible text.


CHAPTER 2: TOKENS AND HOW MODELS READ

Models do not read text as humans do. They read tokens—subword units that are mapped by a tokenizer before the neural network ever sees them. Understanding tokenization is understanding the actual constraint on your thinking.

When you type "The quick brown fox," you see five words. The model never sees words. It sees numbers.

A tokenizer is a function that breaks text into tokens. These tokens are typically subword units. Common words like "the," "is," or "quick" are usually single tokens. Less common words break into multiple tokens. "Fantastical" might tokenize into "Fan," "tas," "tical." A space is itself a token. Punctuation can be tokens. Special characters, numbers, and code each follow their own rules.

The specific tokenization scheme depends on the model family. GPT models use a tokenizer called cl100k_base. Other models use BPE (Byte Pair Encoding), SentencePiece, or proprietary systems. The tokenizer was trained on the same corpus as the model, during pretraining. The tokenizer and the model are paired. You cannot use one without the other.

This matters because tokens are your actual unit of cost, latency, and capacity. When you think you are sending a model 500 words, you are actually sending perhaps 650 tokens (words are typically 1.3 tokens on average). If you send 3 million tokens, they must be processed through the entire network. This takes time. This costs money.

More importantly, tokens are the currency of the context window. A context window is a fixed size. GPT-4 has a context window of up to 128,000 tokens. Claude has 200,000. Some models have 1 million. Every token you use—in system instructions, in examples, in the actual user query—consumes from this fixed pool. If you have 100,000 tokens available and use 40,000 on examples, you have 60,000 left for the user's actual request.

Here is how tokenization affects prompt engineering:

First, repetition in tokens is wasteful. If you say "Do not be rude. Do not be condescending. Do not be aggressive. Do not be dismissive," each "Do not be" is tokens you paid for. It would be better to say "Avoid rudeness, condescension, aggression, and dismissiveness" or even better, "Be respectful and neutral in tone."

Second, specific terms tokenize differently than vague ones. "Generate a list" is 4 tokens. "Output an enumerated series" is 6 tokens. If you repeat the instruction a hundred times across examples, the difference compounds.

Third, the model's understanding of your intent is filtered through what the tokenizer gave it. A rare word that tokenizes into many subword pieces is harder for the model to reason about than a common word. This is why simpler language often works better—it uses fewer tokens, and each token is more familiar (having appeared more frequently in training).

Fourth, whitespace and formatting cost tokens. A blank line is often 2 tokens (line break, line break). Indentation, tabs, multiple spaces—all tokens. Markdown formatting is tokens. This is why compressed prompts can be cheaper than formatted ones, but why formatted prompts are often clearer (and worth the small cost).

Understanding tokenization also helps you anticipate model behavior. When you ask for a list of 100 items, you are asking the model to generate roughly 130 tokens. When you ask for a 3,000-word essay, you are asking for roughly 4,000 tokens. Long outputs take longer to generate. They are also more prone to losing coherence near the end (the model gets tired, so to speak—technically, it is harder to maintain long-range dependencies).

Examples

Prompt 1: Tokenization Inefficiency

Inefficient: "Please be very careful to avoid making any statements that are false or inaccurate. Under no circumstances should you include information that you are not confident about. Be sure to acknowledge when you are uncertain. Do not guess. Do not speculate. Do not assume facts."

Word count: 54 words. Estimated tokens: ~75 tokens.

Better: "Only include information you are confident about. Acknowledge uncertainty explicitly. Do not guess, speculate, or assume."

Word count: 17 words. Estimated tokens: ~25 tokens.

Why this works: The better version communicates the same constraint using one-third the tokens. The model receives the same instruction at a fraction of the cost and often with greater clarity because the instruction is more concise.


Prompt 2: Tokenization and Long Output

You are asking for a 5,000-word article. The model will need to generate approximately 6,500 tokens. If your context window is only 16,000 tokens and you have already used 5,000 tokens on examples and instructions, you have only 11,000 tokens left total. Your article can be at most 8,500 tokens long, or roughly 6,500 words if you are lucky. You asked for 5,000 and you will get it, but you are consuming most of your context window.

Solution: If you need a very long output, use a longer-context model. Or break the task into multiple prompts—one for outline, one for section 1, one for section 2, etc.


Prompt 3: Rare Words and Tokenization

Inefficient: "The phenomenological epistemological framework necessitates a perspicacious exegesis."

Better: "We need a clear explanation of how we know what we know."

The first version uses rare words that tokenize into many subword pieces. The second uses common words that compress into fewer tokens and are more familiar to the model's training data. Both communicate meaning, but the second is cheaper and often clearer.


Failure Modes

Many engineers fail to account for tokenization in their estimates. They count words instead of tokens. A 1,000-word prompt is actually 1,300+ tokens. If multiplied across 100 examples, you are consuming 130,000 tokens in examples alone.

Engineers also fail to recognize that expensive tokenization can hinder reasoning. Using jargon or rare words to sound sophisticated will tokenize poorly and may actually hurt model performance. Simpler language is often better.

Some engineers use fancy formatting (extra spaces, indentation, nested bullets) without realizing they are adding tokens. The visual clarity may not be worth the cost.

Aphorism

You cannot optimize for clarity without understanding tokens. You cannot understand tokens without running them through the tokenizer. Do both, always.


CHAPTER 3: INSTRUCTION HIERARCHY

Not all instructions carry equal weight. Instructions closer to the user's actual query execute with higher priority than instructions buried in system prompts. Effective prompting requires engineering the hierarchy so the most important constraints are most salient.

When you send a message to a language model, there is an implicit hierarchy of which instructions the model follows most reliably.

At the top are instructions immediately adjacent to the task. If you write: "Classify this text: [TEXT HERE] - Respond with only the category name, nothing else," the instruction "Respond with only the category name, nothing else" will be followed with very high reliability. It is right there, at the point of action.

Below that are instructions in the system prompt (or system message), given at the very beginning of the conversation. These are also reliable, but less reliable than instructions at the point of action.

Below that are instructions buried deep in the system prompt, especially if they are contradicted by anything later.

Below that are implicit instructions—things you hoped the model would understand from context but never said explicitly.

At the bottom are instructions that contradict each other. When instructions conflict, models typically follow the most recent one, the one most salient to the current context, or they collapse into confusion.

This hierarchy exists because of how transformers work. Modern language models process sequences token by token and context-dependent. The tokens immediately before an action point have more weight in determining what comes next than tokens far back. This is both blessing and curse. It means you can override earlier instructions with later ones. It also means you must be careful: contradiction at the point of action will override even system-level instructions.

The practical consequence is this: put your most critical constraints as close to the actual task as possible. Do not bury them in a lengthy system prompt and hope they will propagate. Bring them forward. Make them immediate.

Consider the categories of instructions:

System-level instructions are safeguards and general behavior. "You are a helpful assistant. Be honest. Avoid harmful content." These belong in the system prompt.

Task-level instructions specify what work is being done. "Classify this email." "Summarize this document." These belong at the start of the user query.

Format-level instructions specify how the output should look. "Return JSON." "Use numbered list." These belong immediately after the task, or immediately before the task ends.

Edge-case instructions handle specific scenarios. "If the text contains no actionable information, respond with 'INSUFFICIENT DATA.'" These often belong near format instructions, or repeated at the end if they are critical.

Here is the hierarchy visualized as you would write it:

SYSTEM PROMPT (general behavior)
  ↓
USER QUERY BEGINS (task is introduced)
  ↓
CONTEXT (background, examples)
  ↓
SPECIFIC INSTRUCTION (the actual work)
  ↓
FORMAT CONSTRAINT (how to output)
  ↓
EDGE CASES (special behaviors)

Examples

Example 1: Instruction Buried in System Prompt

System Prompt: "You are a helpful assistant. When analyzing text, always note any factual errors you identify, and rate your confidence in your analysis. Always use this format: [ANALYSIS] [CONFIDENCE: 0-100%] [ERRORS: none | list]. Be concise."

User Query: "Analyze this: 'The earth orbits the sun in 365.25 days.'"

Problem: The format instruction is in the system prompt. Some models will follow it. Some will not. It competes with the implicit instruction to "be concise," which can be interpreted as "don't use fancy formatting."

Better:

System Prompt: "You are a helpful assistant. Be honest and concise."

User Query: "Analyze this: 'The earth orbits the sun in 365.25 days.' Use this format: [ANALYSIS] [CONFIDENCE: 0-100%] [ERRORS: none | list]"

Why: The format instruction is now adjacent to the task. It will be followed with higher reliability.


Example 2: Contradictory Instructions at Different Levels

System Prompt: "Always provide complete, detailed explanations."

User Query: "Summarize this 10,000-word article in 100 words."

Problem: These instructions contradict. "Complete and detailed" versus "100 words" cannot both be fully satisfied. The model will either ignore one, produce a confused middle ground, or follow the most recent instruction (the user's).

Better:

System Prompt: "Be helpful and clear. Follow user instructions precisely."

User Query: "Summarize this 10,000-word article in 100 words. Prioritize the key findings over explanation."

Why: The system prompt defers to user instructions. The user query is clear about priorities. No contradiction.


Example 3: Critical Constraint Buried

System Prompt (Long): "You are an expert in machine learning. You understand neural networks, training dynamics, optimization, and statistical analysis. When answering questions about ML, you should consider multiple perspectives and discuss tradeoffs. Always be accurate. [50 more sentences about what an ML expert is] ... When you are wrong, you should acknowledge it..."

User Query: "Can you use dropout in the input layer?"

Problem: The critical instruction "when you are wrong, acknowledge it" is buried in 2,000+ tokens of description. The model may not prioritize it. If the model incorrectly answers "yes, you can use dropout in the input layer" (arguably incorrect), it may not feel the weight of the "acknowledge when wrong" instruction.

Better:

System Prompt: "You are an ML expert. Be accurate. If you are uncertain or wrong, say so explicitly."

User Query: "Can you use dropout in the input layer? If you are uncertain, acknowledge it."

Why: The critical instruction "acknowledge uncertainty" appears twice and is short. It will be followed reliably. It is also at the point of action.


Failure Modes

Many engineers create elaborate system prompts with dozens of instructions, assuming all of them will be followed equally. They will not. Instructions far from the task are effectively weaker.

Engineers also assume that instruction order in the system prompt does not matter. It does, somewhat. Instructions earlier in the system prompt are more stable across multiple turns (in multi-turn conversations), but instructions near the task matter more for that task.

Some engineers bury critical negative instructions ("Do not include opinions") and then are surprised when the model produces opinions. The instruction is there, but it is not salient.

Finally, engineers create instruction hierarchies that contradict. They tell the model to be both creative and factual, to be both concise and complete, to be both personal and professional. These contradictions are often unintentional, but they degrade performance.

Aphorism

The hierarchy of instruction strength is inverse to distance from action. What you whisper into the system prompt and what you shout at the point of task will not carry the same weight. Architect accordingly.


CHAPTER 4: ROLE AND PERSONA DESIGN

Assigning a role to the model shapes its output more powerfully than abstract instruction. A well-designed persona constrains the model's behavior through implicit expectations about what that role entails.

When you tell a model "Be helpful," you get generic helpfulness. When you tell it "You are a professor writing for undergraduate students," you get something more specific. The persona creates a framework. The model understands what a professor does, how a professor communicates, what assumptions a professor makes.

This is not magic. It is that the model has learned, during training, what professors sound like, what tone they use, how they structure explanations. When you invoke that role, you activate those learned patterns.

A good persona serves several functions:

First, it provides an interpretive frame for the task. A persona tells the model how to think about the problem, not just what to do.

Second, it creates implicit constraints on tone, vocabulary, structure, and depth. A philosopher will explain differently than a journalist.

Third, it justifies the constraints you are imposing. "Write like a Shakespeare-era playwright" is a shorthand for a dozen specific stylistic choices. Saying "Use archaic grammar, frequent alliteration, and iambic patterns" is longer and less evocative, though it may be more precise.

Fourth, it reduces ambiguity about edge cases. If something is unclear about the task, the persona provides heuristics for deciding. "If you were a doctor and didn't know what to do, what would you do?" is resolved by thinking like a doctor would think.

The craft of persona design is in selecting a role that is specific enough to constrain behavior but broad enough that the model can fill in the details. "Be a helpful assistant" is too broad—it applies to almost any task. "Be a 47-year-old accountant named Steve who works in Omaha and is mildly irritable" is too narrow—the model will get bogged down in irrelevant personality traits.

The sweet spot is personas that are specific in their relevant dimensions and generic in their irrelevant ones. "You are a machine learning researcher writing for a blog that emphasizes intuition over mathematics" is good. It specifies field (ML), genre (blog), and tone (intuitive). It does not specify age, name, politics, or whether Steve likes baseball.

Personas work best when they are:

Familiar to the model from training. If you invent a completely made-up persona, the model has no framework to work with. "You are a Ziptonian from the planet Zorp" is not familiar. The model will fail or improvise poorly. "You are a xenobiologist" is familiar—the model has seen many descriptions of what xenobiologists do.

Aligned with the actual task. A persona should not fight the task. If you need a technical explanation, assigning a persona of "a five-year-old" will produce something that is not actually accurate, no matter how creative.

Consistent with multiple instruction levels. The persona should not contradict your task-level or format-level instructions. "You are a minimalist poet writing in 500 words" is feasible. "You are a minimalist poet writing 500 words of verbose narrative" is contradictory.

Powerful enough to do the work. Some tasks need no persona. "Extract all names from this text" needs no persona. Other tasks benefit greatly. "Generate a creative product name" benefits from being assigned to a specific role: marketing executive, comedian, philosopher, child.

Examples

Example 1: Generic vs. Specific Persona

Generic: "Generate ideas for a new snack product."

Output: "Here are some snack ideas: (1) a chip-like cracker, (2) a granola bar variation, (3) a yogurt-based product, (4) a nut mix, (5) a dried fruit snack. Each addresses a different market segment."

Specific: "You are a Michelin-starred pastry chef tasked with designing a savory snack that could be sold at a high-end airport store. Consider texture contrast, ingredient quality, and shelf life. Your name is Pierre and you are known for unexpected flavor combinations. Generate 5 concepts."

Output: "Ah, mon ami, let me propose: (1) Parmesan and black truffle shortbread with a salty edge and delicate crunch—sells at 12 euros, justifies premium positioning. (2) A combination of smoked sea salt, dark rye crisps, and cultured butter—takes advantage of the French artisanal trend. (3) Roasted beet and goat cheese wafers with a hint of thyme—vegetable-forward, elegant, memorable. (4) Smoked fish skin chips—controversial, but it is a texture adventure. (5) Miso-caramelized almond brittle—sweet-savory complexity in every bite."

Why the specific persona works: The model now operates within constraints. It thinks about premium positioning, French aesthetics, texture contrast, shelf life. The output is more specific and more useful, even if longer. The persona activated relevant knowledge.


Example 2: Persona for Problem-Solving

Generic: "How should I handle an employee who is always late?"

Output: "You might consider: (1) having a conversation with them, (2) understanding their circumstances, (3) setting clear expectations, (4) documenting issues, (5) considering disciplinary action if needed."

Persona: "You are a human resources director with 15 years of experience managing unions and non-union workforces. You have a reputation for fairness but also for high standards. The employee in question is a strong performer otherwise, and you know their personal situation is complex. How do you handle this?"

Output: "This is delicate. First, I'd pull them aside privately—no judgment, just curiosity. 'I've noticed you're often 15 minutes late. Help me understand what's happening.' Listen. There are usually reasons. Then I'd work backward from their constraints: Can they shift their start time? Do they need flexible arrangements? Is transit an issue? If it's a choice or disrespect, I'd be direct: 'Our policy is clear, and I need to see improvement. Here's what I can offer: a 15-minute flex window if you commit to being within that. But repeated lateness puts your job at risk.' Then I document the conversation. I give them 30 days. If they improve, we move forward. If not, we escalate. Fairness means clear expectations and consistent application."

Why this works: The persona activates real knowledge about workplace dynamics, equity, documentation, and risk management. The answer is more nuanced, more practical, and accounts for context.


Example 3: Persona for Creative Work

Generic: "Write a poem about a bridge."

Output: "A bridge spans the divide, / Connecting two sides that were once apart. / Strong and true, it stands with pride, / A symbol of how we can build what we start."

Persona: "You are Ocean Vuong, writing in a style blending surrealism, Vietnamese-American identity, and intimate observation. Your poems often contain specific sensory details and emotional turbulence beneath beautiful surfaces. Write about a bridge."

Output: "The bridge is a throat clearing. Two banks / hold their breath. I remember my mother / standing at the railing, her hand a small / animal learning not to startle. The metal / is warm—impossible but true. Warmth / means something has been touched so many times / it begins to remember touch. I walk across / and feel the river below, a thing with no sides, / no belonging. The bridge says: you can cross now. / The river says: but at what cost. My mother / said nothing. But her stillness—that was / a kind of speech."

Why this works: The persona activates specific stylistic knowledge. The poem is more distinctive, more layered, more aligned with what Ocean Vuong would actually write.


Failure Modes

Many engineers assign personas that sound good but are too vague. "You are an expert" tells the model to sound confident but provides no actual constraints. "You are a scientist" is slightly better but still broad.

Some engineers assign personas that are contradictory. "You are a cheerful funeral director" or "You are a skeptical religious scholar." Contradiction is sometimes intentional and productive, but often it just creates confused output.

Others assign personas from outside the model's training data or assign personas that are too fictional. "You are a Klingon diplomat" will produce something, but the model is improvising without a clear foundation. Better to use "You are a fierce negotiator who values honor above all else," which the model can ground in more familiar patterns.

Finally, engineers sometimes over-rely on persona as a substitute for explicit instruction. Persona is powerful, but it does not eliminate the need for clear task specification, examples, and format instructions. Persona shapes how the model thinks about a task. It does not replace specification of what task is being done.

Aphorism

A persona is a lever that moves the model's learned behaviors into alignment with your intent. But a lever without a fulcrum—without explicit instruction—can move mountains in the wrong direction.


CHAPTER 5: CONTEXT WINDOWS AS REAL ESTATE

Your context window is finite real estate. Every token you place in it has opportunity cost. The engineering problem is allocating this scarce resource to maximize output quality.

A context window is the maximum sequence of tokens a model can process in a single request. For GPT-4, this is up to 128,000 tokens. For Claude 3.5, it is 200,000. Some newer models have 1 million. These numbers sound large until you start using them.

Here is what 128,000 tokens actually buys you:

  • About 100,000 words of input.
  • Or 50 pages of text.
  • Or one large book.
  • Or 20 small books.
  • Or 100 examples, each with context and expected output.
  • Or a mix of all of the above.

If you are processing a 50,000-word document and using 20,000 tokens for system instructions and examples, you have 108,000 tokens left. Your 50,000-word document consumes approximately 65,000 tokens, leaving you 43,000 tokens for the model to work with and generate output.

The question becomes: how do you allocate your context window to maximize the quality of output?

There is no single right answer, but there are several allocation strategies:

Instruction-heavy allocation uses many tokens for system prompts, examples, and detailed constraints. This works well when the task is complex, ambiguous, or when consistency across many outputs matters. You might use 30,000 tokens for instructions and examples, leaving 98,000 for actual work. This is good for tasks like "classify 1,000 support emails" where consistency is critical.

Context-heavy allocation uses many tokens for background information, documents, or examples that are specific to the user's problem. This works when the task is relatively straightforward but needs grounding in specific facts. You might use 20,000 tokens for instructions and 80,000 for the user's documents.

Output-heavy allocation is for tasks where you need long, detailed outputs and constraints are simple. You might use 10,000 tokens for instructions and reserve 118,000 for generation. This is used for generating long-form content.

Balanced allocation distributes tokens evenly because the task needs all three: complex instructions, substantial input context, and room for output.

The strategic question is: which allocation will produce the best output?

This depends on:

Task complexity. Complex tasks need more instruction tokens. Simple tasks can be instruction-light.

Input document length. If the user's input is short, you have tokens available for examples. If the user's input is long, you must be ruthless about example count.

Output length needed. If you need a 5,000-word essay, reserve tokens accordingly. If you need a one-word answer, you need very few.

Instruction specificity. If you know exactly what you want and can specify it precisely, you need fewer instruction tokens. If the task is novel and the model might misunderstand, invest in examples.

Model capability. Some models are more capable and need fewer examples. Others need more guidance.

The concept of opportunity cost is critical here. Every token you spend on an elaborate system prompt is a token you cannot spend on the user's actual document. Every token spent on a verbose example is a token you cannot spend on generating better output.

Examples

Example 1: A Classification Task

Context window available: 16,000 tokens. Task: Classify 20 customer support tickets into categories.

Naive allocation:

  • System prompt: 500 tokens
  • Task description: 200 tokens
  • Examples: 500 tokens
  • Actual tickets to classify: 3,000 tokens
  • Available for output: 11,800 tokens

This works, but you are underutilizing your window. You could add more examples or more context.

Better allocation:

  • System prompt: 300 tokens
  • Task description: 100 tokens
  • Examples: 2,000 tokens (10 detailed examples instead of 3)
  • Actual tickets to classify: 3,000 tokens
  • Available for output: 10,600 tokens

Why: More examples improve consistency and reduce errors. The tradeoff in output tokens is worth it because your output tokens will be better used (more accurate classifications).


Example 2: A Document Summarization Task

Context window available: 128,000 tokens. Task: Summarize a 50,000-word document.

Poor allocation:

  • System prompt: 2,000 tokens (elaborate instructions on tone, style, length)
  • Examples: 5,000 tokens (detailed examples of other summaries)
  • Document: 65,000 tokens
  • Available for output: 56,000 tokens

You have plenty of output tokens, but you have also spent valuable tokens on instruction. The document itself is the best instruction.

Better allocation:

  • System prompt: 500 tokens (brief, clear instruction)
  • Examples: 1,000 tokens (one or two examples showing what good summaries look like)
  • Document: 65,000 tokens
  • Available for output: 61,500 tokens

Why: The document itself is the guide. You need less instruction. The freed-up tokens give the model more space for a thorough summary. This allocation prioritizes the actual work.


Example 3: A Multi-Step Task

Context window available: 200,000 tokens. Task: Read a research paper, extract findings, evaluate methodology, suggest improvements, and generate a detailed critique.

This task is complex and needs many instruction tokens. But the input document is "only" 15,000 tokens.

Strategic allocation:

  • System prompt: 3,000 tokens (role, responsibilities, what constitutes good critique)
  • Task instruction and framework: 2,000 tokens
  • Examples of critiques: 4,000 tokens (3 detailed examples showing the kind of analysis you want)
  • Document (research paper): 15,000 tokens
  • Available for output: 176,000 tokens

Why: You have invested heavily in instruction because the task is complex. You have room for a very thorough, multi-section critique. The model knows exactly what you want because you showed it.


Failure Modes

Many engineers hoard tokens in their system prompt, creating elaborate, multi-thousand-token instructions that the model will never finish reading carefully. This is wasteful.

Some engineers starve the examples section. They provide one or two examples when five would dramatically improve output. This is false economy—the tokens spent on examples are some of the highest-ROI tokens you can spend.

Others misjudge document length. They think a "50,000-word document" will fit comfortably in a 128,000-token window, forgetting that 50,000 words is actually 65,000+ tokens, plus all the other tokens needed.

Finally, engineers sometimes try to process multiple documents sequentially in a single call without thinking about token consumption. Processing 10 documents of 10,000 words each will use roughly 130,000 tokens just on the documents, leaving little room for anything else.

Aphorism

Context windows are like real estate. You cannot expand the land, but you can allocate it better. The best engineers spend their tokens on what matters most and ruthlessly trim everything else.


CHAPTER 6: FEW-SHOT EXAMPLES

Examples shape model behavior more reliably than instruction alone. A well-chosen example is worth more than a thousand words of description. Few-shot learning is the practice of showing the model what correct looks like.

Few-shot prompting means you provide the model with a small number of examples (typically 2 to 10) of input-output pairs, then ask it to do the same for a new input. This is different from zero-shot, where you provide no examples.

Why does few-shot work so well? Because models are fundamentally pattern-matching systems. When you give an example, you are giving the model a pattern to match. The model learns (within the context window) what the task requires by seeing what correct outputs look like.

Consider a simple task: classifying sentiment.

Zero-shot: "Classify the sentiment of this text as positive, negative, or neutral."

Few-shot:

Text: "I love this product, it changed my life!"
Classification: Positive

Text: "This is just okay, nothing special."
Classification: Neutral

Text: "Completely broken, worst purchase ever."
Classification: Negative

Now classify this:
Text: "The product works as advertised."
Classification:

The few-shot version will almost certainly be more accurate. Why? Because the model has seen the pattern. It knows:

  • What a positive sentiment sounds like (strong positive emotion words)
  • What a negative sentiment sounds like (strong negative emotion words)
  • What a neutral sentiment sounds like (balanced, lukewarm language)
  • The exact format expected (a single word)

Few-shot prompting has several properties that make it powerful:

It disambiguates. If you ask for "sentiment," the model might return "this is positive," "1" (for positive), a score of 0.8, or a paragraph of explanation. Examples show the exact format.

It sets standards. The examples define what good looks like. If you provide examples that are borderline or ambiguous cases, the model learns to handle those. If your examples are clear-cut, the model sets its threshold there.

It overcomes instruction ambiguity. You might describe a style badly. But showing three examples of that style is unambiguous.

It works across model capability levels. Weak models improve most from examples. Strong models improve less, but they still improve.

It transfers reasoning. If your examples show step-by-step reasoning, the model will produce step-by-step reasoning.

The craft of few-shot prompting is in selecting examples that are:

Representative. Your examples should reflect the diversity of the actual task. If you are classifying support tickets and some are about billing, some about technical issues, and some about general feedback, your examples should include all three categories.

Sufficient but not excessive. 3-5 examples often suffice. More than 10 rarely helps and consumes tokens. There is a diminishing return.

Clear and unambiguous. Bad examples confuse the model. If your "positive" sentiment example is ambiguous or your "negative" example contains mixed sentiments, the model will struggle.

Diverse in presentation. If all your examples are short, the model may assume all outputs should be short. If all your examples are the same length, the model may cluster its outputs there. Vary length and complexity.

Aligned with the task distribution. If 80% of your actual inputs are simple and 20% are complex, your examples should roughly reflect this. Do not oversample edge cases unless edge cases matter.

Examples

Example 1: Few-Shot Sentiment Classification

Task: Classify movie reviews into positive, negative, or mixed.

Few-shot prompt (weak):

Text: "Great movie!"
Label: Positive

Text: "Terrible."
Label: Negative

Now label this:
Text: "It had some good scenes but overall I was bored."
Label:

Problem: The training examples are too simple. They do not show the model what a "mixed" sentiment looks like. The model will likely choose positive or negative, not mixed.

Few-shot prompt (stronger):

Text: "This film is a masterpiece of storytelling, cinematography, and acting. I watched it twice."
Label: Positive

Text: "Boring, predictable, and poorly acted. I left halfway through."
Label: Negative

Text: "Some genuinely clever moments, but the pacing was slow and the ending fell flat. I didn't regret watching, but I won't recommend it."
Label: Mixed

Text: "The acting was phenomenal, though the script needed work. Worth watching for the performances alone."
Label: Mixed

Now label this:
Text: "It had some good scenes but overall I was bored."
Label:

Why this works: The model now sees what "mixed" looks like. It sees that mixed reviews contain both positive and negative elements. It will classify the new text correctly.


Example 2: Few-Shot Code Generation

Task: Generate a function that implements a specific algorithm.

Zero-shot:

Generate a Python function that counts the number of vowels in a string.

Output might be syntactically correct but stylistically wrong (not the style you want).

Few-shot:

Examples of functions I want:

def count_occurrences(text, char):
    """Count how many times a character appears in text."""
    return sum(1 for c in text if c == char)

def remove_duplicates(items):
    """Remove duplicates from a list, preserving order."""
    seen = set()
    result = []
    for item in items:
        if item not in seen:
            seen.add(item)
            result.append(item)
    return result

Now generate a similar function:
Generate a Python function that counts the number of vowels in a string.

Output:

def count_vowels(text):
    """Count how many vowels appear in text."""
    return sum(1 for c in text.lower() if c in 'aeiou')

Why this works: The model sees the pattern of style, documentation, and logic. It will produce a function in the same style, not a different style.


Example 3: Few-Shot Structured Output

Task: Extract contact information from unstructured text.

Few-shot:

Input: "Please reach out to Sarah Chen at [email protected] or call 555-0147 between 9 AM and 5 PM EST."
Output: {"name": "Sarah Chen", "email": "[email protected]", "phone": "555-0147", "availability": "9 AM to 5 PM EST"}

Input: "Contact Bob for questions. His number is 555-0923. Email him at [email protected]"
Output: {"name": "Bob", "email": "[email protected]", "phone": "555-0923", "availability": "not specified"}

Input: "Reach out to Maria Rodriguez at [email protected] or message me at 555-7734."
Output:

Why this works: The model sees:

  1. What information to extract
  2. The JSON structure expected
  3. How to handle missing information ("not specified")
  4. How to format data (phone as string, not numeric)

Failure Modes

Many engineers provide too few examples or examples that are all easy cases. The model learns the pattern from easy cases and then struggles with harder cases in the actual task.

Some engineers provide examples that are inconsistent. One example formats a date as "2024-01-15," another as "January 15, 2024," and the model is confused about which format to use.

Others provide examples that are too different from the actual task. Examples that are too simple or too artificial do not transfer well.

Finally, engineers sometimes use examples that are ambiguous or contain contradictions. If you provide an example where the output does not clearly follow from the input, the model will not understand the rule.

Aphorism

An example is a specification without words. Show the model what you want, and it will understand. Tell it what you want, and it will guess. Show beats tell every time.


CHAPTER 7: ZERO-SHOT PRECISION

Zero-shot prompting—using no examples—is possible but requires extraordinary clarity. When you cannot afford examples or must generalize across diverse tasks, zero-shot precision becomes the art of perfect specification without reference.

Zero-shot prompting is the inverse of few-shot. You provide no examples. You rely entirely on instruction and your knowledge of what the model has learned in training.

Zero-shot is necessary in several scenarios:

When context window is scarce. If you have only 4,000 tokens and you need to fit a 3,000-token document, you have no room for examples. You must be clear without them.

When tasks are diverse. If you are processing 10,000 different requests, each requiring a different output format, providing examples for each is infeasible. You must write instructions general enough to work across all tasks.

When the task is novel. For genuinely new tasks the model has not seen in training, examples help less because there are fewer examples in the training data to anchor the model's understanding. You must rely on clear instruction that generalizes the pattern.

When speed or cost matters most. Every example is tokens, which is latency and money. Zero-shot is cheaper and faster.

Zero-shot works because models have learned broad patterns during training. But it requires that you be extraordinarily precise. Where few-shot can rely on "show an example and the model will infer the pattern,"

Sealed by @shingaladeep23 · Pixel 10, 510

Claim a pixel

Comments 0