Define JSON schemas to receive structured, predictable responses from your AI agents instead of free-form text.
$responseSchema
property or add the structuredOutput
method in your agent class for defining more complex schemas.
required
, additionalProperties
, and strict
properties. It’s recommended by OpenAI to set these when defining schemas to get exactly the structure you need.structuredOutput()
method instead of the property, as it provides more flexibility and can include dynamic logic.structuredOutput()
method is a good practice to avoid code duplication and make your code more maintainable.structuredOutput()
method:
responseSchema()
method:
User Profile Generation
Product Recommendations
Content Analysis
required
, skip only properties which are optional in ANY case.additionalProperties
to false
when you want to restrict the output to only the defined propertiesrequired
property for fields that must be present