Prompt Engineering
Advanced

Structured Outputs API Lab

Build a production prompt that returns validated JSON for an enterprise ticket triage workflow.

45 min
2 sections
structured-outputs
json-schema
api
1
2

01. Use schemas for automation

Section 1 of 2

When model output drives workflow automation, free-form prose is not enough. Define a JSON schema with allowed labels, confidence, evidence, and escalation flags. Validate the response before creating tickets, routing work, or notifying customers.

typescript
const triageSchema = {
  type: "object",
  additionalProperties: false,
  required: ["category", "priority", "confidence", "summary", "needsHumanReview"],
  properties: {
    category: {
      type: "string",
      enum: ["bug", "billing", "security", "feature_request", "unknown"],
    },
    priority: {
      type: "string",
      enum: ["low", "normal", "high", "urgent"],
    },
    confidence: {
      type: "number",
      minimum: 0,
      maximum: 1,
    },
    summary: {
      type: "string",
      maxLength: 240,
    },
    needsHumanReview: {
      type: "boolean",
    },
    evidence: {
      type: "array",
      items: { type: "string", maxLength: 160 },
    },
  },
} as const;
Back to Course