Structured Output in Pipelines

Use structured output with AI pipelines for type-safe, composable workflows. Combine the power of runnables with guaranteed data structures for robust AI applications.

Use structured output with AI pipelines for type-safe, composable workflows. Combine the power of runnables with guaranteed data structures for robust AI applications.

🚀 Quick Start

🏗️ Structured Output Flow

Basic Pipeline with Structured Output

// Define your data structure
class Person {
    property name="firstName" type="string";
    property name="lastName" type="string";
    property name="age" type="numeric";
}

// Create pipeline with structured output
pipeline = aiModel( "openai" )
    .structuredOutput( new Person() )

// Run and get typed result
person = pipeline.run( "Extract: John Doe, age 30" )
println( person.getFirstName() )  // "John"

🔧 Pipeline Methods

.structuredOutput( schema )

Define structured output for the pipeline:

.structuredOutputs( schemas )

Extract multiple structures in one request:

.schema( jsonSchema )

Use raw JSON schema for full control:

Message Templates with Structured Output

Combine reusable prompts with typed outputs:

Chaining with Transformations

Process structured output through multiple stages:

Multi-Step Pipelines

Use structured output at different pipeline stages:

Working with Arrays

Extract lists of structured items:

Parallel Processing

Process multiple items with structured output:

Streaming with Structured Output

Stream progressive responses, get structured final result:

Integration with AI Agents

Agents with structured responses:

Memory with Structured Data

Store and retrieve structured output:

Advanced Patterns

Conditional Structured Output

Choose output structure based on input:

Validation Pipeline

Validate and retry with structured output:

Enrichment Pipeline

Add data to structured output:

Aggregate Pattern

Collect structured results:

Best Practices

1. Position Structured Output at Output Stage

2. Use Transform for Post-Processing

3. Type Your Pipeline Variables

4. Cache Pipelines

Error Handling

Schema Validation Errors

Runtime Errors

Performance Tips

1. Batch Processing

2. Simple Schemas

3. Streaming for Long Responses

Last updated