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
- Python
- TypeScript
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.
import { Custodian } from "@custodianlabs/sdk";
const app = await new Custodian({ model: "gpt-6-luna", systemPrompt: "You triage support tickets." })
.addExamples([
{ user: "My order has not arrived.", assistant: "Category: Shipping. Priority: High." },
{ user: "I want to change my email.", assistant: "Category: Account. Priority: Low." },
])
.deploy();
console.log((await 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.
- Python
- TypeScript
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'}
import { Custodian } from "@custodianlabs/sdk";
const app = await new Custodian({
model: "gpt-6-luna",
systemPrompt: "Classify the support ticket.",
responseSchema: {
type: "object",
properties: {
category: { type: "string" },
priority: { type: "string", enum: ["low", "medium", "high"] },
},
required: ["category", "priority"],
},
}).deploy();
const reply = await app.chat("I was charged twice.");
console.log(reply?.rawPayload.structured_output);
// { category: "Billing", priority: "high" }
Learn more
- Prompts and few-shot examples: zero-shot, one-shot and few-shot, writing good examples, and how schemas work.