Skip to main content

Few-shot and structured output

Teach an agent a format with examples, or get JSON back with a schema.

This example: a support ticket classifier. It tags each incoming ticket with a category and priority, as text for people or JSON for your code.

Example (replies vary)
With examples:
You: I was charged twice.
Agent: Category: Billing. Priority: High.

With a response schema:
You: I was charged twice.
structured_output: {"category": "Billing", "priority": "high"}

Teach a format with examples​

from custodian_labs import Custodian

app = 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."},
],
).deploy()

print(app.chat("I was charged twice.").response) # Category: Billing. Priority: High.

Get JSON back with a schema​

Set response_schema to a JSON Schema and the reply carries a parsed structured_output alongside the text.

from custodian_labs import Custodian

app = Custodian(
model="gpt-6-luna",
system_prompt="Classify the support ticket.",
response_schema={
"type": "object",
"properties": {
"category": {"type": "string"},
"priority": {"type": "string", "enum": ["low", "medium", "high"]},
},
"required": ["category", "priority"],
},
).deploy()

print(app.chat("I was charged twice.").structured_output)
# {'category': 'Billing', 'priority': 'high'}
Learn more