Can't get structured output after update to latest version
I'm using @mastra/client-js from an app to call my agent.
client side:
const outputSchema = z.object({
code: z.string().describe('code'),
});
const response = await agent.generate({
messages: [
{
role: 'user',
content: [
{
type: 'text',
text: 'user prompt',
providerOptions: providerOptions,
},
],
},
],
structuredOutput: {
schema: outputSchema,
},
});
console.log(JSON.stringify(response.object));
const result: TerraformResourceCode = response.object;
Agent side ("mastra": "^0.16.0, @mastra/core": "^0.21.0):
export const myagent = new Agent({
model:getModel,
memory: memory,
instructions: async ({ runtimeContext, mastra }) => {
return AGENT_INSTRUCTION;
},
defaultStreamOptions: (context) => {
console.log("defaultStreamOptions called");
return context;
},
// defaultVNextStreamOptions: (context) => {
// console.log("defaultVNextStreamOptions called");
// return {
// maxSteps: 5,
// structuredOutput: resourceConfigurationCodeSchema
// }
// },
defaultGenerateOptions: (context) => {
console.log("defaultGenerateOptions called");
return {
maxSteps: 5,
onStepFinish: logStepDetails,
}
},
tools: {
...mcpTools,
},
});
I also lost tools logging5 Replies
📝 Created GitHub issue: https://github.com/mastra-ai/mastra/issues/8875
GitHub
[DISCORD:1427947352622370890] Can't get structured output after upd...
This issue was created from Discord post: https://discord.com/channels/1309558646228779139/1427947352622370890 I'm using @mastra/client-js from an app to call my agent. client side: ` const out...
Hi @Supasteevo, are you able to provide more details? What isn't working? What exactly are you seeing?
Hi @Daniel Lew .
Sure, basically I'm trying to generate a structured output when calling the agent via
generate()
function. Currently, the response does not contain any Object
property, only text
.
I'm using anthropic/claude-sonnet-4
model.
I'm not sure if I should also set any output options on the agent side, and/or add response format in agent instructions. But it used to work at some point and now it doesn't anymoreCan you give me more detail on how your'e running it? Code examples would help. It's possible that that model does not support response format, and you need to set
jsonPromptInjection: true
https://mastra.ai/en/docs/agents/overview#response-formatAgent Overview | Agents | Mastra Docs
Overview of agents in Mastra, detailing their capabilities and how they interact with tools, workflows, and external systems.
Thanks you for your answer.
jsonPromptInjection
fixed the issue. I don't know why it was working before without this option, if anything changed on the model provider side or in Mastra.
By the way, code example was provided in my initial message: https://discord.com/channels/1309558646228779139/1427947352622370890/1427947352622370890