Skip to main content
Tasks support various response formats to structure the output according to your needs. You can specify the expected format using the response_format parameter.

String Response (Default)

Pydantic Model Response

Complex Nested Models

Response Format Types

TypeDescriptionUse Case
strSimple text responseBasic questions, summaries
BaseModelStructured Pydantic modelComplex data, analysis results
NoneNo format constraintFlexible responses

Best Practices

  • Structured Data: Use Pydantic models for complex, structured responses
  • Field Validation: Leverage Pydantic’s built-in validation for data integrity
  • Optional Fields: Use Optional types for fields that might not always be present
  • Nested Models: Break down complex responses into smaller, reusable models
  • Type Hints: Always provide clear type hints for better IDE support and validation
  • Default Values: Set appropriate default values for optional fields