Structured demonstrations are a few-shot prompting technique where input-output examples are presented in a highly organized, often schema-enforced format—such as a table, a strict template, or a labeled data structure—to make the intended task and output format explicitly clear to the model. This method reduces ambiguity by visually separating the input, the reasoning steps (if used), and the desired output, thereby providing a stronger signal for in-context learning than unstructured text. It is a foundational practice within context engineering for achieving deterministic, formatted responses like JSON, XML, or YAML from a model.
Glossary
Structured Demonstrations

What is Structured Demonstrations?
A core technique in prompt engineering for improving the reliability and format accuracy of large language model outputs.
The primary engineering goal is to enforce structured output generation by providing a crystal-clear input-output mapping within the prompt's context. This is distinct from simply providing examples; it involves designing the demonstrations to act as a template or grammar that the model can parse and replicate. Effective use of structured demonstrations directly mitigates formatting hallucinations, improves task specification clarity, and is a key component of retrieval-augmented ICL systems where dynamically retrieved examples must conform to a predictable schema for reliable integration.
Key Characteristics of Structured Demonstrations
Structured demonstrations are few-shot examples presented in a highly organized format to make the input-output mapping explicitly clear to the model, enhancing task performance and output consistency.
Explicit Schema Enforcement
Structured demonstrations enforce a strict schema or template across all examples. This could be a table with labeled columns, a JSON object with consistent keys, or an XML template with defined tags. The rigid format eliminates ambiguity about what constitutes a valid input and its corresponding output, directly teaching the model the required data structure. For instance, instead of free-text examples, a demonstration for extracting product details might be presented as a table with columns for Product Name, Price, and SKU.
Deterministic Output Formatting
The primary goal is to guarantee the model generates outputs in a pre-defined, machine-readable format. By repeatedly showing the model the exact same output structure, it learns to replicate that format reliably. This is critical for downstream integration, where the model's response must be parsed by another software system. Common enforced formats include:
- JSON or YAML for API responses
- CSV-like rows for data extraction
- HTML snippets with specific class names
- Structured Query Language (SQL) statements
Reduced Ambiguity & Hallucination
The highly organized nature of structured demonstrations minimizes interpretive ambiguity. When examples are presented in a clear, tabular, or key-value format, the model has less room to misinterpret the task or invent (hallucinate) irrelevant details. This contrasts with unstructured, paragraph-style examples where the mapping between input concepts and output elements is implicit and must be inferred. Structured demonstrations act as a strong regularization technique during inference, constraining the model's output space to the demonstrated schema.
Efficient Context Utilization
Structured formats are often more token-efficient than verbose natural language descriptions. A well-designed table can convey multiple complex relationships in fewer tokens than equivalent prose. This efficiency allows for more demonstrations to fit within a model's fixed context window, potentially improving performance through many-shot learning. It also makes the prompt easier for both the model and human developers to scan and understand, improving debuggability.
Programmatic Generation & Scaling
Because they follow a strict template, structured demonstrations can be programmatically generated from existing datasets. This enables the automated creation of hundreds of consistent examples for prompt augmentation. Engineers can write scripts to sample from a database and format the records into the required demonstration schema, allowing for rapid iteration and testing of different demonstration sets. This scalability is a key advantage over manually crafting narrative examples.
Contrast with Unstructured Examples
It is defined by what it is not. An unstructured demonstration might be a conversational snippet or a paragraph where the task is implied. A structured demonstration makes the task explicit through formatting. For example:
- Unstructured: "User: 'What's the weather in Tokyo?' Assistant: 'The current temperature in Tokyo is 72°F.'"
- Structured: "
Input City: Tokyo->Output: {'city': 'Tokyo', 'temp_f': 72, 'conditions': 'Clear'}" The latter leaves no doubt about the required key-value mapping and output format.
How Structured Demonstrations Work
A technical breakdown of structured demonstrations, a core technique in context engineering that uses rigidly formatted examples to guide model output.
Structured demonstrations are a few-shot prompting technique where input-output examples are presented in a highly organized, often non-narrative format—such as a table, a strict schema, or a templated list—to make the intended task and output structure explicitly clear to a language model. This method reduces ambiguity by visually separating the input-output mapping and enforcing consistent example formatting, which helps the model generalize the underlying pattern more reliably than from prose examples alone. The rigid format acts as a scaffold, priming the model for structured output generation like JSON or CSV.
The effectiveness of structured demonstrations stems from their ability to leverage a model's pre-training on code and formatted data, activating its capacity for pattern recognition over syntactic templates. By presenting demonstrations as a labeled dataset within the prompt, the technique provides a stronger signal for conditional generation, reducing the cognitive load of parsing natural language instructions. This approach is particularly powerful for tasks requiring deterministic formatting, such as data extraction, classification with a fixed label space, or generating API calls, as it minimizes hallucination and improves output consistency across varied queries.
Common Formats and Examples
Structured demonstrations are few-shot examples presented in a highly organized format to make the input-output mapping explicitly clear to the model. Below are key formats and their implementation details.
Tabular Format
Presenting examples in a clear table is one of the most effective structured formats. It visually separates inputs from outputs and can include column headers that act as implicit instructions.
Key Characteristics:
- Uses pipe (
|) characters or other delimiters to create columns. - Column headers (e.g.,
Input Text,Sentiment) define the task. - Each row is a complete demonstration.
Example for Sentiment Analysis:
code| Review Text | Sentiment | |-------------|-----------| | "The battery life is incredible." | Positive | | "The app crashes constantly." | Negative | | "The product was delivered on time." | Neutral |
This format explicitly shows the mapping from text to label, reducing ambiguity.
Strict Schema (JSON/XML)
Enforcing a specific data serialization format like JSON or XML within demonstrations teaches the model the exact output structure required.
Key Characteristics:
- Demonstrations are valid JSON objects or XML snippets.
- The schema (key names, nesting) is consistent across all examples.
- Often paired with a system prompt instructing the model to output in the same format.
Example for Entity Extraction (JSON):
codeInput: "Meet John Doe at Google HQ in Mountain View tomorrow." Output: {"people": ["John Doe"], "organizations": ["Google"], "locations": ["Mountain View"], "dates": ["tomorrow"]} Input: "The conference with Microsoft is scheduled for October 5th in London." Output: {"people": [], "organizations": ["Microsoft"], "locations": ["London"], "dates": ["October 5th"]}
This provides a template the model can replicate precisely.
Labeled I/O with Delimiters
Using clear, consistent labels and delimiters (like Input: and Output:) for each example creates a predictable pattern for the model to follow.
Key Characteristics:
- Each demonstration is a self-contained block.
- The same labels and formatting are used for every example.
- Whitespace (like line breaks) separates demonstrations.
Example for Text Rewriting:
codeInput: Make this professional: "hey can u send the report?" Output: "Hello, could you please send the report?" Input: Make this professional: "thx for the help" Output: "Thank you for your assistance."
The rigid structure makes the task specification and input-output mapping unmistakable.
Step-by-Step Reasoning (CoT)
For complex reasoning tasks, structured demonstrations can include the intermediate reasoning steps, formatted to show a logical progression.
Key Characteristics:
- Demonstrations decompose the problem.
- Steps are often prefixed with terms like
Step 1,Reasoning:, orTherefore:. - The final answer is clearly demarcated (e.g.,
### Answer:).
Example for Math Word Problem:
codeQ: A bakery had 12 loaves. They sold 5 in the morning and 3 in the afternoon. How many are left? A: Let's think step by step. - Start with 12 loaves. - Morning: 12 - 5 = 7 loaves remaining. - Afternoon: 7 - 3 = 4 loaves remaining. ### Answer: 4
This format primes the model to generate its own chain of thought before the final answer.
Rule + Example Pairs
This format explicitly states a transformation rule followed by one or more examples that instantiate it, combining task specification with demonstration.
Key Characteristics:
- A general instruction or rule is given first.
- Examples show the application of that rule.
- Effective for teaching syntactic or stylistic transformations.
Example for Date Formatting:
codeRule: Convert all dates to the format YYYY-MM-DD. Example 1: Input: "The event is on Jan 15, 2023." Output: "The event is on 2023-01-15." Example 2: Input: "We met last March 3rd." Output: "We met last 2023-03-03." (assuming current year context)
This structure clarifies the abstract rule and its concrete application.
Comparative Demonstrations
Showing both correct and incorrect examples for a task provides contrastive guidance, helping the model understand boundaries and common failure modes.
Key Characteristics:
- Pairs a valid demonstration with an invalid one.
- Often includes annotations like
(Correct)or(Incorrect: reason). - Useful for safety, formatting, and classification tasks with subtle distinctions.
Example for Content Moderation:
codeInput: "I disagree with your political stance." Output: SAFE (Correct - permissible criticism) Input: "I will find and hurt you for your political stance." Output: UNSAFE (Correct - violent threat) Input: "Your politics are stupid." Output: UNSAFE (Incorrect: While rude, this is an insult, not a threat. Should be SAFE.)
This method defines the label space more precisely by showing edge cases.
Structured vs. Unstructured Demonstrations
A comparison of two core approaches for providing in-context examples to a language model, highlighting how organizational format impacts clarity, consistency, and model performance.
| Feature | Structured Demonstrations | Unstructured Demonstrations |
|---|---|---|
Core Format | Highly organized schema (e.g., table, strict JSON, XML). | Free-form, natural language narrative. |
Input-Output Delineation | Explicit, often using visual separators like column headers or tags. | Implicit, relying on the model to infer the mapping from prose. |
Consistency Across Examples | Extremely high; identical format enforced for all examples. | Variable; phrasing and structure can differ between examples. |
Primary Use Case | Tasks requiring strict output formatting (JSON/XML generation, data extraction). | Creative writing, open-ended Q&A, tasks where output format is fluid. |
Cognitive Load on Model | Low. The schema reduces ambiguity, letting the model focus on content. | High. The model must parse narrative to deduce the task pattern. |
Resistance to Format Hallucination | Very high. Explicit structure strongly guides the output format. | Low. Model may invent its own inconsistent output structure. |
Ease of Human Parsing | High. Data is scannable and machine-readable by design. | Low. Requires reading full text to understand the example. |
Scalability for Many Examples | High. Tabular formats are compact and preserve context window efficiency. | Low. Narrative examples consume more tokens, reducing the number that can fit. |
Frequently Asked Questions
Structured demonstrations are a core technique in few-shot learning, designed to make task requirements explicitly clear to a language model through highly organized examples. This FAQ addresses common questions about their design, implementation, and impact on model performance.
A structured demonstration is a few-shot example presented in a highly organized, often schema-enforced format—such as a table, a list with strict delimiters, or a JSON-like structure—to make the input-output mapping explicitly clear to a large language model (LLM). Unlike free-text examples, structured demonstrations use consistent formatting, labels, and whitespace to visually and semantically separate the task's components, reducing ambiguity and guiding the model toward the desired output format. This technique is a form of in-context learning (ICL) that leverages the model's pattern recognition capabilities on formatted data, effectively priming it to replicate the structure in its response. It is a key method for achieving deterministic output formatting without fine-tuning, making it essential for prompt engineering in production systems where API responses must adhere to a strict schema.
Key characteristics include:
- Consistent Delimiters: Use of markers like
Input:,Output:,###, or---. - Tabular Layouts: Presenting examples in rows and columns for comparative tasks.
- Explicit Labeling: Clearly tagging each part of the example (e.g.,
"query","answer"). - Schema Preview: Sometimes including a brief description of the expected JSON or XML structure before the examples.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Structured demonstrations are a core technique within the broader family of in-context learning methods. These related concepts define the mechanisms for conditioning a model's behavior without updating its parameters.
In-Context Learning (ICL)
In-context learning (ICL) is the foundational paradigm where a pre-trained language model performs a new task by conditioning its response on examples provided within the prompt, without any gradient updates to its weights. It is the super-category that encompasses all few-shot techniques.
- Mechanism: The model uses the attention mechanism over the prompt's context to infer the task pattern.
- Parameter-Free: The model's billions of parameters remain frozen; adaptation happens purely at inference-time.
- Core Dependency: Performance hinges on the model's pre-existing knowledge and its ability to recognize patterns in the provided context.
Demonstration Selection
Demonstration selection is the strategic process of choosing which specific examples to include in a few-shot prompt to maximize performance. It directly impacts the clarity of the input-output mapping the model must learn.
- Key Criteria: Selection is based on exemplar quality, demonstration diversity, and relevance to the target query.
- Advanced Techniques: Methods include semantic similarity selection and k-NN demonstration retrieval, where a vector database finds examples whose embeddings are closest to the query.
- Retrieval-Augmented ICL: This architecture dynamically retrieves demonstrations for each query from a large datastore, moving beyond a static prompt.
Example Formatting
Example formatting refers to the syntactic and structural presentation of the instruction-example pairs within the prompt. It is the practical implementation layer of structured demonstrations.
- Purpose: Clear formatting (using delimiters, indentation, labels) reduces ambiguity and makes the task specification explicit.
- Common Patterns: Using XML tags, JSON blocks, or markdown tables to delineate inputs from outputs.
- Template-Based Examples: Generating demonstrations by populating a strict schema ensures consistency, which is critical for structured output generation tasks like API call simulation.
Instruction-Example Pair
An instruction-example pair is the atomic unit of a few-shot prompt, combining a natural language task description with a concrete demonstration of that task.
- Structure: Typically follows the pattern:
Instruction: <task description>\nInput: <example_input>\nOutput: <example_output>. - Function: The instruction provides the abstract task specification, while the example provides a grounded instance of the label space and expected format.
- Best Practice: Effective pairs are unambiguous, correct, and representative of the task's complexity. Multiple pairs create the structured demonstrations that prime the model.
Parameter-Free Adaptation
Parameter-free adaptation is the characteristic ability of a model to adjust its behavior for a new task using only the information in the prompt, while its pre-trained weights remain completely frozen. This is the defining trait of in-context learning.
- Contrast with Fine-Tuning: Unlike parameter-efficient fine-tuning (PEFT), no weight updates occur.
- Inference-Only: The entire adaptation happens during the frozen model inference pass, making it highly efficient and reversible.
- Scope: Encompasses zero-shot, one-shot, few-shot, and many-shot learning, all of which are forms of gradient-free learning.
Dynamic Few-Shot Prompting
Dynamic few-shot prompting is an adaptive technique where the composition of the prompt's demonstration set is determined at runtime for each individual query, rather than using a fixed set.
- Driver: Enabled by retrieval-augmented ICL architectures that perform query-example matching in real-time.
- Advantage: Allows for adaptive demonstration counts and content, optimizing for both relevance and available context window space.
- System Design: Requires an embedding model and a vector store (e.g., a vector database) to retrieve the most semantically similar examples on-the-fly.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us