{"record":{"id":"5b4e7de1b2e5d20f","repo":"mastra-ai/mastra","slug":"agent-generate-legacy-structured-output-not-suppor","errorCode":"AGENT_GENERATE_LEGACY_STRUCTURED_OUTPUT_NOT_SUPPORTED","errorMessage":"This method does not support structured output. Please use generate() instead.","messagePattern":"This method does not support structured output\\. Please use generate\\(\\) instead\\.","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/agent-legacy.ts","lineNumber":963,"sourceCode":"        });\n        return afterResult;\n      },\n    };\n  }\n\n  /**\n   * Legacy implementation of generate method using AI SDK v4 models.\n   * Use this method if you need to continue using AI SDK v4 models.\n   */\n  async generateLegacy<\n    OUTPUT extends ZodSchema | JSONSchema7 | undefined = undefined,\n    EXPERIMENTAL_OUTPUT extends ZodSchema | JSONSchema7 | undefined = undefined,\n  >(\n    messages: MessageListInput,\n    generateOptions: AgentGenerateOptions<OUTPUT, EXPERIMENTAL_OUTPUT> = {},\n  ): Promise<OUTPUT extends undefined ? GenerateTextResult<any, EXPERIMENTAL_OUTPUT> : GenerateObjectResult<OUTPUT>> {\n    if ('structuredOutput' in generateOptions && generateOptions.structuredOutput) {\n      throw new MastraError({\n        id: 'AGENT_GENERATE_LEGACY_STRUCTURED_OUTPUT_NOT_SUPPORTED',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text: 'This method does not support structured output. Please use generate() instead.',\n      });\n    }\n\n    const defaultGenerateOptionsLegacy = await Promise.resolve(\n      this.capabilities.getDefaultGenerateOptionsLegacy({\n        requestContext: generateOptions.requestContext,\n      }),\n    );\n\n    const mergedGenerateOptions: AgentGenerateOptions<OUTPUT, EXPERIMENTAL_OUTPUT> = {\n      ...defaultGenerateOptionsLegacy,\n      ...generateOptions,\n      experimental_generateMessageId:\n        defaultGenerateOptionsLegacy.experimental_generateMessageId ||","sourceCodeStart":945,"sourceCodeEnd":981,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/agent-legacy.ts#L945-L981","documentation":"generateLegacy() is the deprecated v1 generate path. It does not support structured output, so passing a `structuredOutput` option (or OUTPUT schema) throws immediately with this MastraError. Use the modern generate() API which supports structured output natively.","triggerScenarios":"Calling the deprecated agent.generateLegacy() with `{ structuredOutput: z.object(...) }` (or a JSON schema) in AgentGenerateOptions.","commonSituations":"Migrating old code that used generate() with a schema after upgrading, or code generators/examples pinned to the legacy API attempting to add structured output.","solutions":["Switch to agent.generate() with the structuredOutput option (or use generate() with a Zod schema) — the modern API supports structured output.","If you must stay on generateLegacy() temporarily, remove the structuredOutput option and parse the text output manually."],"exampleFix":"// before\nconst result = await agent.generateLegacy(prompt, { structuredOutput: schema });\n// after\nconst result = await agent.generate(prompt, { structuredOutput: schema });","handlingStrategy":"validation","validationCode":"function assertLegacySafe(opts: { structuredOutput?: unknown }) {\n  if ('structuredOutput' in opts && opts.structuredOutput) {\n    throw new Error('structuredOutput requires agent.generate(), not generateLegacy()');\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await agent.generateLegacy(msgs, opts);\n} catch (err) {\n  if ((err as any).id === 'AGENT_GENERATE_LEGACY_STRUCTURED_OUTPUT_NOT_SUPPORTED') {\n    return agent.generate(msgs, opts); // automatic fallback to modern API\n  }\n  throw err;\n}","preventionTips":["Migrate all generateLegacy call sites to generate(); grep the repo for 'generateLegacy'.","Add a lint/CI rule banning generateLegacy with structuredOutput options.","Keep the OUTPUT type parameter on generate() to retain typing after migration."],"tags":["agent","deprecated-api","structured-output","migration"],"backgroundTag":"unsupported-legacy-api","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}