EchoStash
Docs

Schema

Define structured output schemas for JSON responses

Schema: Structured Output

The [#SCHEMA] block defines a JSON Schema for structured LLM output, forcing the model to respond in a specific format.

Basic Syntax

schema-basic.echo
[#ROLE system]
Analyze the following text and extract structured information.
[END ROLE]

[#SCHEMA]
summary:
  type: string
  description: Brief summary of the content
  required: true
sentiment:
  type: string
  enum: [positive, negative, neutral]
  required: true
confidence:
  type: number
  description: Confidence score from 0 to 1
keywords:
  type: array
  description: Key topics mentioned
[END SCHEMA]

[#ROLE user]
{{text}}
[END ROLE]

Schema Rules

  • Only one [#SCHEMA] block per template
  • Cannot be inside a conditional — it is always present
  • No variable interpolation inside schema blocks
  • Schema content is not included in message output

Supported Types

string, number, boolean, array, object. Each property supports type, description, required, and enum.

Output Format

The schema is rendered as standard JSON Schema:

json
{
  "type": "object",
  "properties": {
    "summary": { "type": "string", "description": "Brief summary of the content" },
    "sentiment": { "type": "string", "enum": ["positive", "negative", "neutral"] },
    "confidence": { "type": "number", "description": "Confidence score from 0 to 1" },
    "keywords": { "type": "array", "description": "Key topics mentioned" }
  },
  "required": ["summary", "sentiment"]
}

Usage with renderMessages()

const result = await echo.renderMessages(template, { text: "Great product!" })

result.schema    // The JSON Schema object
result.messages  // Messages without schema content

How Providers Use It

When sending to OpenAI, the schema is passed as response_format. The LLM is forced to output valid JSON matching the schema:

// Sending to OpenAI with structured output
await openai.chat.completions.create({
  model: "gpt-4o",
  messages: result.messages,
  response_format: {
    type: "json_schema",
    json_schema: { schema: result.schema }
  }
})