Structured Output and Complex Task Prompts
🎯 Introduction
Suppose a customer sends your support system:
I bought two T-shirts for ¥120 in total and want to return them.
You want AI to extract the product, quantity, amount, and intent for further processing. A long prose response makes these values difficult for programs to read consistently.
In another case, a customer describes a product fault. Support must identify the issue, determine what still needs verification, and compose an appropriate reply. “Handle the support issue” is often too vague.
We will combine two methods: structured output defines how results are returned; task decomposition defines how work is organized and checked.
🧱 What Is Structured Output?
Structured output asks a model to return results in a predefined data structure rather than free-form prose.
For the opening message:
{
"product": "T-shirt",
"quantity": 2,
"amount": 120,
"intent": "return"
}
Programs can read fixed fields. However, amount is the amount mentioned by the customer, not a verified order total. Structured output organizes data without automatically establishing its truth.
🧱 Defining Field Requirements
“Return JSON” is insufficient. The model may change field names, omit fields, or guess missing values.
Design requirements in this order.
Step 1: Identify the Information Needed
Define the business goal: extract product name, purchased quantity, mentioned amount, and customer intent.
This determines which fields are needed. Do not add fields simply because the model could extract more.
Step 2: Define Fields and Types
For example:
Always return exactly these four fields, without adding or removing fields:
- product: product name, string or null
- quantity: purchased quantity, integer or null
- amount: amount mentioned by the customer, number or null
- intent: customer intent, string or null
This standardizes names and allows null for every missing field. Defining missing-value behavior for only some fields leaves others open to invented values.
Step 3: Define Missing-Information Behavior
Suppose the customer says:
I want to return the T-shirt.
No quantity or amount is provided. Expect:
{
"product": "T-shirt",
"quantity": null,
"amount": null,
"intent": "return"
}
Explicitly require: extract only information stated in the message; return null for unspecified fields without guessing.
Step 4: Assemble a Testable Prompt
Extract the product, quantity, amount, and intent from the customer message.
Return only one JSON object with exactly these fields:
- product: product name, string or null
- quantity: purchased quantity, integer or null
- amount: amount mentioned by the customer, number or null
- intent: customer intent, string or null
Use only information in the customer message. Return null for values not explicitly provided.
Do not guess or add fields.
Do not include explanations or Markdown code fences.
Customer message: I bought two T-shirts for ¥120 in total and want to return them.
Run the prompt and check field completeness, types, missing values, and consistency with the source message.
🧱 Why Break Complex Tasks into Steps?
The previous task only extracted information. Now consider:
The left side of my headphones has no sound. I contacted support two days ago and nobody has replied. I want to request a return.
“Handle this support message” could produce a reply that overlooks the unanswered support request or promises a refund without order information or return rules.
Break the task into steps with individually checkable results.
| Step | Work | Expected result |
|---|---|---|
| 1. Extract facts | Record only explicitly stated information | No sound on the left; no support reply for two days; customer wants a return |
| 2. Identify the issue and missing information | Identify the request and matters that cannot be confirmed | Product fault and return request; order details and return rules need verification |
| 3. Generate a reply | Use known facts and verification needs | Apologize, acknowledge the request, explain verification needs, and avoid promising a refund outcome |
Specify all three steps and their outputs:
Complete these tasks using the customer message:
1. Extract known facts without adding information the customer did not provide.
2. Identify the after-sales issue and list information still requiring verification.
3. Use the first two results to write a short, polite support reply.
Without order records and return rules, do not guarantee a refund or successful return.
Return only one JSON object containing:
- facts: array of known facts
- issue_type: issue type string
- needs_verification: array of matters to verify
- reply: customer reply string
Customer message:
The left side of my headphones has no sound. I contacted support two days ago and nobody has replied. I want to request a return.
This is an expected output example, illustrating the target rather than an actual model run:
{
"facts": [
"The left side of the headphones has no sound",
"The customer reports receiving no support reply for two days",
"The customer wants to request a return"
],
"issue_type": "Product fault and return request",
"needs_verification": [
"Order records",
"Store return policy"
],
"reply": "We apologize for the inconvenience. We understand the reported headphone fault and your return request. We need to verify the order and return conditions before confirming how to proceed."
}
The program can check omissions, issue classification, verification needs, and unsupported promises separately.
Task decomposition separates fact extraction, issue identification, and response generation. Structured output returns those results in fixed fields for reading and checking.
Three steps do not require three model calls. This can still be one prompt and one request. The purpose is to define work and checkable results, not request lengthy internal reasoning.
Simple tasks need not be split unnecessarily. Decomposition is useful when several parts require separate handling and review.
❓ Knowledge Check
Q1: Can we trust data just because the JSON satisfies every field requirement?
No. Structural validity and factual correctness differ. A message can supply product information and a claimed amount, but actual order status and refund outcomes still require business-system verification.
Q2: Why define types and missing-value rules together?
Users may omit information. Requiring an integer quantity without defining missing-value behavior may encourage guesses or unexpected output.
Q3: Does task decomposition always require multiple model calls?
No. One request can specify multiple steps and return their results. The actual number of calls depends on the task and application design.
🧪 Exercise
A customer writes:
I bought headphones last week. Today I noticed there is no sound on the left, and I would like after-sales support.
Complete two tasks:
- Structured output: write a prompt returning
product,problem, andpurchase_date. Accept only an explicit calendar date ornullforpurchase_date; do not guess a date from “last week.” - Task decomposition: split handling into fact extraction, issue and verification identification, and a reply without unverified promises. Require checkable results for each.
Send your prompt to an AI tool and check compliance.
Success criteria: The first task should return "headphones", "no sound on the left", and null. The second should preserve stated facts, identify missing order records and support rules, and avoid guaranteeing returns or refunds. If it fails, identify the violated constraint, revise, and test again.
🎉 Congratulations! You can define structured results and break complex tasks into checkable steps. Next, we will organize effective context.
Few-Shot Examples
Compare zero-shot and few-shot prompting, and guide classification with clear rules and input-output examples.
Context Engineering
Learn how context engineering relates to prompt engineering, and how to select sources, verify versions, organize context, and retain information in long conversations.
