Skip to content

Structured Responses: Python vs YAML

This example demonstrates two ways to define structured responses in LLMling-agent:

  • Using Python Pydantic models
  • Using YAML response definitions
  • Type validation and constraints
  • Agent integration with structured outputs

How It Works

  1. Python-defined Responses:

  2. Use Pydantic models

  3. Full IDE support and type checking
  4. Best for programmatic use
  5. Inline field documentation

  6. YAML-defined Responses:

  7. Define in configuration

  8. Include validation constraints
  9. Best for configuration-driven workflows
  10. Self-documenting fields

Example Output:

Python-defined Response:
Main point: User expresses enthusiasm for new feature
Is positive: true

YAML-defined Response:
Sentiment: positive
Confidence: 0.95
Mood: excited

This demonstrates:

  • Two ways to define structured outputs
  • Validation and constraints
  • Integration with type system
  • Trade-offs between approaches

Open in Pydantic Playground