Structured output sometimes not getting followed in agent generate()
I have an agent taht uses generate() to output a structured response and I notice that this sometimes results in an erro that gets logged as this in my generate() function onError handler:
{ category: SYSTEM domain: AGENT id: OUTPUT_SCHEMA_VALIDATION_FAILED}
{ category: SYSTEM domain: AGENT id: OUTPUT_SCHEMA_VALIDATION_FAILED}
It looks like the output is undefined based on the error we catch in our try-cacth around this workflow step:
Type validation failed: Value: undefined. Error message: Validation failed
Type validation failed: Value: undefined. Error message: Validation failed
For context, we're using gpt-4.1 and here is the agent code that lives in one of our workflow steps:
This happens pretty sparsely but is still a real issue since this is a critical step in the workflow. Some ideas I have that may help (though still unsure) are: - using .strict() in my schema definition - defining
structuredOutput.instructions
structuredOutput.instructions
to give custom formatting instructions - using a different model provider in