{"record":{"id":"715a248352b6447b","repo":"mastra-ai/mastra","slug":"map-results-step-unsupported-model","errorCode":"MAP_RESULTS_STEP_UNSUPPORTED_MODEL","errorMessage":"Tripwire handling requires a v2/v3 model","messagePattern":"Tripwire handling requires a v2/v3 model","errorType":"error_code","errorClass":"MastraError","httpStatus":null,"severity":"error","filePath":"packages/core/src/agent/workflows/prepare-stream/map-results-step.ts","lineNumber":127,"sourceCode":"          if (saveQueueManager && memoryData.thread?.id) {\n            await saveQueueManager.flushMessages(messageList, memoryData.thread.id, memoryConfig);\n          }\n        }\n\n        return options.onStepFinish?.({ ...props, runId });\n      },\n      ...(memoryData.tripwire && {\n        tripwire: memoryData.tripwire,\n      }),\n    };\n\n    // Check for tripwire and return early if triggered\n    if (result.tripwire) {\n      try {\n        const agentModel = await capabilities.getModel({ requestContext: result.requestContext! });\n\n        if (!isSupportedLanguageModel(agentModel)) {\n          throw new MastraError({\n            id: 'MAP_RESULTS_STEP_UNSUPPORTED_MODEL',\n            domain: ErrorDomain.AGENT,\n            category: ErrorCategory.USER,\n            text: 'Tripwire handling requires a v2/v3 model',\n          });\n        }\n\n        const modelOutput = await getModelOutputForTripwire<OUTPUT>({\n          tripwire: memoryData.tripwire!,\n          runId,\n          ...createObservabilityContext({ currentSpan: agentSpan }),\n          options: options,\n          model: agentModel,\n          messageList,\n        });\n\n        // End agent span with tripwire information after fallback completes\n        agentSpan?.end({","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/agent/workflows/prepare-stream/map-results-step.ts#L109-L145","documentation":"In the map-results step of agent streaming workflows, when the model raised a tripwire (guardrail violation), Mastra must re-read the model via capabilities.getModel to handle the tripwire consistently. If the resolved model is not a supported LanguageModelV2/V3 instance, tripwire handling cannot proceed, so this MastraError (USER category) is thrown.","triggerScenarios":"A stream finishes with result.tripwire === true while the agent's resolved model (possibly a custom wrapper, legacy v1 model, or non-standard provider object returned from getModel) fails isSupportedLanguageModel — i.e. not an AI SDK LanguageModelV2/V3.","commonSituations":"Using a custom model wrapper that doesn't implement the v2/v3 spec; passing a legacy model after upgrading Mastra/AI SDK; dynamic getModel returning a mocked or wrong-typed object in tests; mixing provider packages of mismatched major versions.","solutions":["Return a genuine AI SDK LanguageModelV2/V3 model from your getModel capability implementation","Unwrap custom wrappers and pass the underlying provider model instance","Upgrade legacy v1 model adapters to v2/v3-compatible provider packages","Align @mastra/core, ai, and @ai-sdk/* provider versions so the model spec matches","Remove mocks/stubs that fail isSupportedLanguageModel in production paths"],"exampleFix":"// before\ngetModel: async () => myCustomWrapper,\n// after\ngetModel: async () => myCustomWrapper.underlyingLanguageModelV3, // or the raw @ai-sdk provider model","handlingStrategy":"validation","validationCode":"import { isSupportedLanguageModel } from '@mastra/core/agent';\nconst model = await capabilities.getModel({ requestContext });\nif (!isSupportedLanguageModel(model)) {\n  throw new Error('Agent model must be an AI SDK LanguageModelV2/V3 for tripwire handling');\n}","typeGuard":"function isV2OrV3Model(m: unknown): boolean {\n  return !!m && typeof m === 'object' && 'doStream' in m &&\n    [2, 3].includes((m as { specificationVersion?: string }).specificationVersion as number) ||\n    !!m && typeof m === 'object' && 'doStream' in m;\n}","tryCatchPattern":"try {\n  await workflow.start();\n} catch (e) {\n  if ((e as Error).message.includes('Tripwire handling requires a v2/v3 model')) {\n    // replace the model adapter with a v2/v3-compatible one and rerun\n  }\n}","preventionTips":["Return raw provider models (not wrappers) from getModel","Keep @ai-sdk provider packages on v2/v3 specification versions","Avoid mocks in production model resolution paths","Add a startup check that isSupportedLanguageModel(getModel())"],"tags":["tripwire","guardrails","model-version","agent-workflow"],"backgroundTag":"unsupported-language-model-version","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}