{"record":{"id":"cd652eb71cf75efa","repo":"mastra-ai/mastra","slug":"structured-output-processor-model-required","errorCode":"STRUCTURED_OUTPUT_PROCESSOR_MODEL_REQUIRED","errorMessage":"StructuredOutputProcessor requires a model to be provided either in options or as fallback","messagePattern":"StructuredOutputProcessor requires a model to be provided either in options or as fallback","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/processors/processors/structured-output.ts","lineNumber":62,"sourceCode":"  private useAgent = false;\n  private errorStrategy: 'strict' | 'warn' | 'fallback';\n  private fallbackValue?: OUTPUT;\n  private isStructuringAgentStreamStarted = false;\n  private jsonPromptInjection?: boolean | 'system' | 'inline' | 'auto';\n  private providerOptions?: ProviderOptions;\n  private logger?: IMastraLogger;\n\n  constructor(options: StructuredOutputOptions<OUTPUT>) {\n    if (!options.schema) {\n      throw new MastraError({\n        id: 'STRUCTURED_OUTPUT_PROCESSOR_SCHEMA_REQUIRED',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text: 'StructuredOutputProcessor requires a schema to be provided',\n      });\n    }\n    if (!options.model) {\n      throw new MastraError({\n        id: 'STRUCTURED_OUTPUT_PROCESSOR_MODEL_REQUIRED',\n        domain: ErrorDomain.AGENT,\n        category: ErrorCategory.USER,\n        text: 'StructuredOutputProcessor requires a model to be provided either in options or as fallback',\n      });\n    }\n\n    this.schema = options.schema;\n    this.structuringModel = options.model;\n    this.useAgent = options.useAgent ?? false;\n    this.errorStrategy = options.errorStrategy ?? 'strict';\n    this.fallbackValue = options.fallbackValue;\n    this.jsonPromptInjection = options.jsonPromptInjection;\n    this.providerOptions = options.providerOptions;\n    this.logger = options.logger;\n    this.structuringInstructions = options.instructions || this.generateInstructions();\n    // Create internal structuring agent as fallback (used when no explicit agent is set)\n    this.structuringAgent = new Agent({","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/processors/processors/structured-output.ts#L44-L80","documentation":"StructuredOutputProcessor delegates the actual generation to a language model. It can take the model from `options.model`; if none is supplied (and no fallback is available), it has nothing to run, so the constructor throws a MastraError with id STRUCTURED_OUTPUT_PROCESSOR_MODEL_REQUIRED (domain AGENT, category USER).","triggerScenarios":"`new StructuredOutputProcessor({ schema })` with no `model` key, or `model: undefined` — e.g. a model created conditionally, an invalid provider string that resolves to undefined, or forgetting to pass the model when the processor is not attached to an agent that would supply a fallback.","commonSituations":"Refactoring to share one model instance across processors and dropping the reference, model factory returning undefined on missing API key, examples that rely on agent-level fallback models while using the processor standalone.","solutions":["Pass a model instance or model string: `new StructuredOutputProcessor({ schema, model: 'openai/gpt-4o' })`.","If constructing per-request, confirm the model factory actually returns a model (check API key/env vars).","Attach the processor to an Agent configured with a model so the fallback path applies.","Validate the model value is non-undefined before constructing the processor."],"exampleFix":"// before\nnew StructuredOutputProcessor({ schema: MySchema });\n// after\nnew StructuredOutputProcessor({ schema: MySchema, model: 'openai/gpt-4o' });","handlingStrategy":"validation","validationCode":"if (!model) throw new TypeError('StructuredOutputProcessor: model is required');\nconst processor = new StructuredOutputProcessor({ schema, model });","typeGuard":"function hasModel<T>(o: StructuredOutputOptions<T>): o is StructuredOutputOptions<T> & { model: NonNullable<StructuredOutputOptions<T>['model']> } {\n  return Boolean(o.model);\n}","tryCatchPattern":"try {\n  processor = new StructuredOutputProcessor(opts);\n} catch (e) {\n  if (e instanceof MastraError && e.id === 'STRUCTURED_OUTPUT_PROCESSOR_MODEL_REQUIRED') {\n    processor = new StructuredOutputProcessor({ ...opts, model: DEFAULT_MODEL });\n  } else throw e;\n}","preventionTips":["Create the model instance before processors and pass the same reference everywhere.","Check model factory calls for undefined returns (missing API keys).","Prefer agent-attached usage only when the agent reliably configures a fallback model."],"tags":["configuration","model","structured-output","constructor"],"backgroundTag":"missing-required-option","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}