Skip to main content

Prompts, few-shot examples and structured output

There are three ways to control what an agent says. You can tell it, show it, or give it a form to fill in.

TechniqueAnalogyUse it for
System promptA job descriptionRole, tone, rules and what to do when unsure
Few-shot examplesShowing a new hire a few finished ticketsA consistent format or style that's hard to describe
Structured outputA form with fixed boxesAnswers your code needs to read, as JSON

The system prompt: tell it​

The system prompt is a standing instruction the agent follows in every conversation. The user never sees it.

A good system prompt covers:

  • Role. "You are the support assistant for Acme's billing team."
  • Audience and tone. "Customers are not technical. Be short and friendly."
  • Rules. "Never promise a refund. Point people to the refund form instead."
  • What to do when unsure. "If the answer isn't in the documents, say so and offer to connect them with a human."

The last point matters most. Without it, a model may guess.

Zero-shot, one-shot and few-shot: show it​

A shot is one example: a sample user message with the ideal answer.

ApproachWhat you give the agentResult
Zero-shotInstructions only, no examplesWorks for general tasks. The format can drift.
One-shotOne exampleThe agent copies its shape. It may copy it too closely.
Few-shotTwo to five varied examplesThe agent picks up the pattern and applies it to new messages.

Examples are powerful because models are excellent at continuing a pattern. It's often easier to show a format than to describe it.

Zero-shot. The prompt says "Classify the ticket." Replies vary, such as "This seems like a billing issue" or "Category: billing (high priority?)".

Few-shot. Add two examples:

UserAssistant
My order has not arrived.Category: Shipping. Priority: High.
I want to change my email.Category: Account. Priority: Low.

Now "I was charged twice" gets "Category: Billing. Priority: High." Same format, every time.

Custodian(
model="gpt-6-luna",
system_prompt="You triage support tickets.",
examples=[
{"user": "My order has not arrived.", "assistant": "Category: Shipping. Priority: High."},
{"user": "I want to change my email.", "assistant": "Category: Account. Priority: Low."},
],
)

Writing good examples​

  • Vary them. Cover different kinds of message, such as a short one, a long one and an unusual one. Similar examples teach the agent less.
  • Make every example perfect. The agent copies mistakes as faithfully as good answers.
  • Keep it to a few. Two to five is usually enough. Each example adds to every request's size and cost.
  • Show the hard cases. Include an example of what to do when the answer is unknown, or when a request is out of scope.

Structured output: give it a form​

When software reads the answer, not a person, you want reliable JSON rather than sentences. A response schema is a description of the exact fields you want, written as JSON Schema.

{
"type": "object",
"properties": {
"category": { "type": "string" },
"priority": { "type": "string", "enum": ["low", "medium", "high"] }
},
"required": ["category", "priority"]
}

This says: return an object with a category text field and a priority field that must be low, medium or high. The agent's reply then includes a parsed structured_output, such as {"category": "Billing", "priority": "high"}, alongside the normal text.

On a squad, a response_schema on the squad shapes the final answer, whatever the individual agents return.

Which should I use?​

You wantUse
The agent to behave a certain waySystem prompt
Answers in a consistent style or layoutSystem prompt plus few-shot examples
Data your code can readStructured output

They work well together. A common setup is a clear prompt, two or three examples and a schema.

See it in code: Few-shot and structured output template.