Chapter 6: User prompts for LLMs
Introduces user prompts as the context source that expresses a user’s immediate intent and guides the model toward a specific outcome.
After this chapter you will be able to
- User Prompt Role. Explain that a user prompt is one of the six context sources supplied to an LLM and that it expresses immediate user intent to guide the model toward a specific outcome.
- Prompts as task specifications. Explain why an effective user prompt states the task and sets expectations rather than leaving the model to infer the user's intent. Use the section's two context-engineering prompts to illustrate the difference.
- User prompts in assembled context. Distinguish a prompt passed directly to a model from one incorporated into an application's assembled context. Explain why prompt engineering is only one part of context engineering.
- Iterative prompt design. Explain why prompt design is more than asking a question and describe how testing, observing, and refining a prompt can improve it.
- Clear outcome and direction. Explain why a prompt should state the intended outcome clearly and how constraints such as audience and purpose make the response more targeted.
- Explicit output format. Explain why a prompt should specify the output structure, especially when another system will consume the response.
- Input and output examples. Explain how examples of desired inputs and outputs help a model follow a prompt.
- Task steps and boundaries. Describe how to break a complex objective into smaller steps and why delimiters can help within a prompt.
- Untrusted input and prompt injection. Explain why user and external text must be treated as untrusted input, distinguish direct from indirect prompt injection, and describe the prompt-level defense taught here.
- Versioned prompt templates. Explain why production prompts should be parameterized, version-controlled templates rather than scattered hardcoded strings, and what that enables teams to do.
- Prompting patterns and principles. Explain how prompting techniques relate to prompting principles and affect a model's interpretation of a task.
- Role as interpretive lens. Explain how assigning a persona, professional role, or domain expertise shapes a model’s tone, perspective, and evaluation criteria. Distinguish a role set persistently in system instructions from one set for an individual user prompt.
- Learning from prompt examples. Explain how input-output demonstrations in a prompt let a model infer a task and continue the pattern without updating its weights.
- Dynamic demonstration selection. Trace how dynamic few-shot prompting selects relevant examples in production and describe its stated caching drawback.
- Intermediate reasoning before answers. Explain how chain-of-thought prompting guides a model through intermediate checks before a final answer, using the phone-support eligibility example.
- ReAct thought action observation loop. Trace how a ReAct prompt moves from identifying missing information to emitting a tool action, receiving an observation, and using it to answer.
- Sequential prompt chain. Explain how prompt chaining breaks a complex workflow into model calls whose outputs feed later calls, using the review-to-response example.
- Chain failure safeguards. Explain why an error in an early chain step can affect later steps and how checkpoints between calls can mitigate that risk.
- Reasoning Model Prompt Focus. Explain why explicit reasoning procedures are often unnecessary for reasoning models and describe what their prompts should specify instead.
- Prompt framework structure and value. Explain how a prompt framework organizes what is sent to an LLM and why its repeatability matters.
- Ten-component prompt structure. Describe how the framework assembles task framing, supporting material, instructions, interaction context, and response requirements into a prompt.
- Stable-to-dynamic component ordering. Explain why the framework puts stable material first and volatile material near the end.
- Lightweight framework tradeoffs. Distinguish the completeness of the 10-step structure from the speed and readability of lighter frameworks, and describe the different emphases of COSTAR and RTF.
- Production prompt consistency. Explain why agreeing on a prompt structure matters more in production than choosing a particular framework.
- Prompt experimentation and management. Distinguish interactive prompt experimentation from managing prompts in production. Explain why production prompts should be treated as managed artifacts rather than strings embedded in code.
- Application framework approaches. Distinguish frameworks that combine prompts with application components from DSPy's declarative approach to building and optimizing prompts.
- Few-shot ticket normalization. Explain how the ticket normalizer uses two labeled input-output examples to show the model a support ticket schema, then asks it to follow the same pattern for a new bug report.
- Support reply prompt chain. Trace how an enterprise support inquiry moves from structured analysis through SLA policy resolution to a final customer reply, and explain why these are separate stages rather than one model call.
- DSPy signature and modules. Explain how the math tutor uses one DSPy signature for its task specification while different modules supply the reasoning strategy, without hand-writing prompt text.
- CoT and ReAct selection. Distinguish how the two tutor variants work and explain which kinds of tasks favor CoT or ReAct.
- Structured prompt builder workflow. Describe how the context-aware prompt builder helps create, compare, and reuse prompts across the chapter’s frameworks.
- User prompts within context. Explain why a user prompt is not usually the only context a reliable application gives an LLM.
What it builds on
- User prompt (chapter 1) · Introduces the user prompt as a context source.
- The system prompt (chapter 2) · The use of system prompts to provide persistent instructions.
- Retrieval-augmented generation (chapter 3) · The idea of using retrieval to find relevant material.
- Tools (chapter 4) · Assumes familiarity with tools available to AI agents.
Section by section
Introduction
Introduces user prompts as the context source that expresses a user’s immediate intent and guides the model toward a specific outcome.
- User Prompt Role: Explain that a user prompt is one of the six context sources supplied to an LLM and that it expresses immediate user intent to guide the model toward a specific outcome.
Why it matters: This is the role that prompt design in the rest of the chapter aims to serve.
Key terms: user prompts, immediate user intent, context sources
6.1 User prompt
This section explains how a user prompt supplies context, why specific prompts produce more useful responses, and how prompts fit into an application's broader context.
- Prompts as task specifications: Explain why an effective user prompt states the task and sets expectations rather than leaving the model to infer the user's intent. Use the section's two context-engineering prompts to illustrate the difference.
Why it matters: A more specific request gives the model less to guess about the answer you want. - User prompts in assembled context: Distinguish a prompt passed directly to a model from one incorporated into an application's assembled context. Explain why prompt engineering is only one part of context engineering.
Why it matters: In an application, improving the user's wording addresses only one component of what the model receives.
Key terms: user prompt, prompt engineering, underspecified, structured and constrained, context management layer, context engineering
6.2 Best practices for prompt design
Prompt design sets the conditions for an LLM’s answer and improves through testing and refinement.
- Iterative prompt design: Explain why prompt design is more than asking a question and describe how testing, observing, and refining a prompt can improve it.
Why it matters: Treating a prompt as something to test and refine helps you spot why an answer missed the mark.
Key terms: prompt design, testing, observing, and refining, context
6.2.1 Core design principles
This section explains four principles for making prompts more directed, predictable, and usable in larger systems.
- Clear outcome and direction: Explain why a prompt should state the intended outcome clearly and how constraints such as audience and purpose make the response more targeted.
Why it matters: Stating what you want gives the model a more useful target than a broad request does. - Explicit output format: Explain why a prompt should specify the output structure, especially when another system will consume the response.
Why it matters: A defined format makes model output more dependable as part of a larger system. - Input and output examples: Explain how examples of desired inputs and outputs help a model follow a prompt.
Why it matters: An example can make an otherwise ambiguous instruction concrete. - Task steps and boundaries: Describe how to break a complex objective into smaller steps and why delimiters can help within a prompt.
Why it matters: Smaller steps and clear boundaries make a complex request easier for the model to follow.
Key terms: Give direction, clear intent, style, persona, Specify format, Markdown prose, JSON, schema, Provide examples, input and output format
6.2.2 Production considerations
This section explains how production prompts should handle untrusted inputs and be managed as versioned software assets.
- Untrusted input and prompt injection: Explain why user and external text must be treated as untrusted input, distinguish direct from indirect prompt injection, and describe the prompt-level defense taught here.
Why it matters: A production prompt may encounter text that looks like instructions but must not be allowed to govern the application. - Versioned prompt templates: Explain why production prompts should be parameterized, version-controlled templates rather than scattered hardcoded strings, and what that enables teams to do.
Why it matters: Managing prompts like software makes production changes easier to review, deploy, reverse, and test.
Key terms: untrusted input, prompt injection, direct injection, indirect injection, explicit delimiters, defensive instructions, prompt templates, versioned software assets, runtime variable placeholders, regression testing
6.3 Prompting techniques
Introduces prompting techniques as repeatable patterns that turn prompting principles into structured context for model tasks.
- Prompting patterns and principles: Explain how prompting techniques relate to prompting principles and affect a model's interpretation of a task.
Why it matters: This gives you a way to think about why prompting techniques are useful before looking at individual techniques.
Key terms: prompting principles, prompting strategies, structuring context
6.3.1 Role prompting
This section explains how assigning a role to an LLM focuses its response and when that focus is useful.
- Role as interpretive lens: Explain how assigning a persona, professional role, or domain expertise shapes a model’s tone, perspective, and evaluation criteria. Distinguish a role set persistently in system instructions from one set for an individual user prompt.
Why it matters: A well-chosen role can steer the model toward the perspective the task calls for. - Value of specialized roles: Describe how the cybersecurity-analyst role changes the network-configuration assessment, and explain when role prompting is more or less useful.
Why it matters: Role prompting is worth using when a task benefits from a particular expert viewpoint, rather than as a default for every request.
Key terms: role prompting, system instructions, user prompt, specialized domain perspectives
6.3.2 Few-shot prompting
This section explains how few-shot examples teach a model a task within a prompt, and the token and caching trade-offs of selecting those examples.
- Learning from prompt examples: Explain how input-output demonstrations in a prompt let a model infer a task and continue the pattern without updating its weights.
Why it matters: It distinguishes giving a model examples at request time from training it on those examples. - Demonstration token trade-off: Describe the typical number of demonstrations given for straightforward transformations and the context they consume on each request.
Why it matters: Adding examples has a context cost even when only a few are needed. - Dynamic demonstration selection: Trace how dynamic few-shot prompting selects relevant examples in production and describe its stated caching drawback.
Why it matters: It explains why production prompts may select examples per query rather than always include the same ones.
Key terms: few-shot prompting, input-output demonstrations, in-context learning, inference pass, demonstrations, tokens, context consumption, dynamic few-shot prompting, retrieval layer, demonstration store
6.3.3 Chain-of-thought prompting
Explains how chain-of-thought prompting uses intermediate reasoning to reach a decision, illustrated by a support-policy check, and identifies its benefits and costs.
- Intermediate reasoning before answers: Explain how chain-of-thought prompting guides a model through intermediate checks before a final answer, using the phone-support eligibility example.
Why it matters: The intermediate checks make it easier to see how a decision follows from the policy. - Reasoning benefits and token costs: Describe the auditability and decision-quality benefits of intermediate reasoning, alongside its context-engineering cost.
Why it matters: Showing the steps can help, but it consumes more tokens, time, and money. - Limits of arithmetic reasoning: Distinguish CoT's help with logical decomposition from exact calculation, and state when computation should be delegated.
Why it matters: A step-by-step explanation is not a substitute for reliable computation.
Key terms: chain-of-thought (CoT) prompting, intermediate reasoning steps, reasoning tokens, audit trail, token consumption, latency, cost, logical decomposition, exact arithmetic, external tools
6.3.4 ReAct prompting
This section explains how ReAct prompting alternates reasoning and tool use, and why the resulting trace has a context cost.
- ReAct thought action observation loop: Trace how a ReAct prompt moves from identifying missing information to emitting a tool action, receiving an observation, and using it to answer.
Why it matters: The distinction between emitting a tool action and executing it explains how ReAct answers with fresh evidence rather than a guess. - ReAct trace context cost: Explain the benefit and context-window cost of accumulating ReAct observations and intermediate steps.
Why it matters: Tool evidence can improve an answer while making the available context fill up.
Key terms: ReAct, Thought - Action - Observation loop, agent harness, observation, context window, intermediate steps
6.3.5 Prompt chaining
Explains how prompt chaining splits a workflow into sequential model calls and why production chains may need checks between calls.
- Sequential prompt chain: Explain how prompt chaining breaks a complex workflow into model calls whose outputs feed later calls, using the review-to-response example.
Why it matters: Separate, inspectable steps can make a complex prompt workflow easier to manage. - Chain failure safeguards: Explain why an error in an early chain step can affect later steps and how checkpoints between calls can mitigate that risk.
Why it matters: Checking an intermediate result can prevent a bad early output from undermining the rest of the chain.
Key terms: prompt chaining, sequential model calls, intermediate outputs, prompt budgets, failure propagation, validation checkpoints, schema parsing, confidence filters, fallback logic
6.3.6 Other prompting techniques
6.3.7 Prompting and reasoning models
Explains how reasoning models shift prompting away from prescribed thought steps and toward specifying the task and its context.
- Reasoning Model Prompt Focus: Explain why explicit reasoning procedures are often unnecessary for reasoning models and describe what their prompts should specify instead.
Why it matters: It helps you give a reasoning model what it needs without unnecessarily prescribing how it should think.
Key terms: reasoning models, explicit CoT, ToT, self-consistency, task specification, grounding data
6.4 Prompt frameworks
Defines prompt frameworks as repeatable structures and explains why their predictability supports prompt reuse and evaluation.
- Prompt framework structure and value: Explain how a prompt framework organizes what is sent to an LLM and why its repeatability matters.
Why it matters: A consistent prompt structure makes it easier to reuse prompts and compare their results fairly.
Key terms: prompt framework, templatable, versionable, comparable across runs
6.4.1 10-step prompt structure
Introduces a ten-component prompt structure, explains why its components are ordered from stable to dynamic context, and clarifies how to write useful reasoning guidance.
- Ten-component prompt structure: Describe how the framework assembles task framing, supporting material, instructions, interaction context, and response requirements into a prompt.
Why it matters: The structure helps you give each part of a prompt a clear purpose rather than mixing everything together. - Stable-to-dynamic component ordering: Explain why the framework puts stable material first and volatile material near the end.
Why it matters: The ordering supports reuse of stable context while keeping changing information close to the response. - Task-specific reasoning guidance: Distinguish task-specific verification guidance from a generic instruction to think step by step or to output a reasoning trace.
Why it matters: Concrete checks tell the model what matters for the task without requiring it to display its reasoning.
Key terms: task context, tone context, background data, documents, and images, detailed task description and rules, examples, conversation history, stable material, volatile parts, cached, generated tokens
6.4.2 Lightweight frameworks
This section contrasts lightweight prompt frameworks with the 10-step structure and explains why using one structure consistently matters in production.
- Lightweight framework tradeoffs: Distinguish the completeness of the 10-step structure from the speed and readability of lighter frameworks, and describe the different emphases of COSTAR and RTF.
Why it matters: The framework should provide enough structure for the task without making an everyday prompt unnecessarily verbose. - Production prompt consistency: Explain why agreeing on a prompt structure matters more in production than choosing a particular framework.
Why it matters: A consistent structure makes changes to production prompts easier to inspect and evaluate.
Key terms: 10-step structure, lightweight frameworks, COSTAR, RTF, single agreed structure, diffable, testable, comparable
6.5 Prompting tools
This section distinguishes tools for experimenting with prompts, managing them in production, and building applications around them.
- Prompt experimentation and management: Distinguish interactive prompt experimentation from managing prompts in production. Explain why production prompts should be treated as managed artifacts rather than strings embedded in code.
Why it matters: The tools a team needs change when a prompt moves from exploration into a production system. - Lifecycle platforms and observability: Describe how prompt lifecycle platforms connect prompt development with evaluation and production observability.
Why it matters: Production traces and evaluation results can be considered alongside the prompts being developed. - Application framework approaches: Distinguish frameworks that combine prompts with application components from DSPy's declarative approach to building and optimizing prompts.
Why it matters: Frameworks can turn a prompting technique into part of a complete application, but they do not all approach prompts the same way.
Key terms: interactive environments, managed artifacts, prompt versioning, prompt lifecycle platforms, evaluation runs, traces collected from production, AI frameworks, LangChain, LlamaIndex, DSPy
6.6 Hands-on
This section introduces the hands-on exercises and points readers to the companion repository for complete scripts, dependencies, and run commands.
6.6.1 Few-shot ticket normalizer
Shows how a few labeled examples in a prompt guide an LLM to turn noisy bug reports into a consistent support ticket format.
- Few-shot ticket normalization: Explain how the ticket normalizer uses two labeled input-output examples to show the model a support ticket schema, then asks it to follow the same pattern for a new bug report.
Why it matters: The examples show the model what consistent ticket output should look like without requiring a long explanation in the prompt.
Key terms: labeled examples, repeating input-output pattern, support ticket schema
6.6.2 Prompt chaining for support replies
Illustrates how a support workflow chains two model calls with application logic between them to produce a policy-grounded customer reply.
- Support reply prompt chain: Trace how an enterprise support inquiry moves from structured analysis through SLA policy resolution to a final customer reply, and explain why these are separate stages rather than one model call.
Why it matters: Separating analysis, policy resolution, and writing makes clear what each part of the support workflow contributes.
Key terms: prompt chaining, inquiry analysis, policy resolution, response generation, SLA response targets
6.6.3 Prompting with DSPy: CoT vs ReAct
Shows how DSPy implements the same math-tutor task with reusable CoT and ReAct modules, and explains when to choose each strategy.
- DSPy signature and modules: Explain how the math tutor uses one DSPy signature for its task specification while different modules supply the reasoning strategy, without hand-writing prompt text.
Why it matters: Separating the task specification from the strategy lets the same task use different prompting approaches. - CoT and ReAct selection: Distinguish how the two tutor variants work and explain which kinds of tasks favor CoT or ReAct.
Why it matters: The task’s need for tools or intermediate checks guides the choice of strategy.
Key terms: DSPy, signature, module, CoT, ReAct, calculator tool
6.6.4 Using prompt frameworks
This section shows how a prompt builder turns framework components into reusable prompts and places user prompts alongside other context sources.
- Structured prompt builder workflow: Describe how the context-aware prompt builder helps create, compare, and reuse prompts across the chapter’s frameworks.
Why it matters: The builder makes a framework’s structure easier to follow and its resulting prompts easier to reuse. - User prompts within context: Explain why a user prompt is not usually the only context a reliable application gives an LLM.
Why it matters: It connects prompt design to the broader context the application supplies.
Key terms: context-aware prompt builder, prompt frameworks, Prompt sample, Copy prompt, Export, Import, user prompts, context sources, instructions, retrieved knowledge
6.7 Summary
Where this is used later
- Context management (chapter 7) · Builds on the distinction between user input and the broader context an application manages.
- Safety and security (chapter 9) · defensive prompt design, which this section says can reduce misinterpretation but cannot enforce security boundaries
- Evaluation datasets (chapter 8) · Evaluation datasets provide cases against which prompt changes can be regression-tested.
- Context as code with versioned prompt templates (chapter 9) · Applies versioned prompt templates as a context-as-code practice.
- Reusable prompts as context assets (chapter 11) · Prompting techniques that can be combined for a task.
- Context compression (chapter 7) · Motivates managing growing traces through context compression.
- Evaluation (chapter 8) · Explains why comparable prompts are a precondition for evaluation.
- PromptOps (chapter 9) · Prompt operations builds on the need to manage prompts consistently in production.
Concepts explained in this chapter
- promptA prompt is an input supplied to a language model to elicit a response or guide its behavior.
- prompt engineeringPrompt engineering is the practice of designing and refining inputs to a language model to influence the quality and character of its output.
- demonstrationA demonstration supplied in a model's context to guide its response to a task.
- output formatAn output format is the required structure or representation of a model-generated result.
- prompt frameworkA repeatable structure specifying the information and instructions a prompt contains and their order.
- DSPyDSPy is an open-source framework for programming language-model systems with declarative modules and signatures that can be optimized against metrics and examples.
- prompt injectionPrompt injection is an attack that attempts to manipulate an AI system by introducing instructions into its input or context.
- versioningThe practice of tracking and managing changes to files so changes can be reviewed and earlier versions restored.
- AI frameworkA software framework that provides reusable components and abstractions for building AI-powered applications.
- ReActReAct is an agent reasoning pattern that alternates between internal reasoning and external actions such as tool invocation.
- reasoning modelA language model optimized to solve demanding problems by generating intermediate reasoning steps before a final output.
- schemaA schema is a formal specification of the permitted structure, fields, and constraints of data or outputs.
- chain-of-thoughtStep-by-step reasoning is a reasoning technique that decomposes a complex task into a sequence of smaller logical operations.
- evaluation datasetAn evaluation set is a collection of test cases and expected or judged outcomes used to assess a system's performance.
- tool descriptionA tool definition specifies a tool's name, purpose, and expected arguments so a system can determine how to invoke it.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.
