mastra-ai/mastra · error
Unsupported JSON Schema target: "${options.target}". Support
Error message
Unsupported JSON Schema target: "${options.target}". Supported targets are: ${supportedTargets.join(', ')} What it means
convertToJsonSchema in the zod-v3 standard-schema adapter maps an options.target (e.g. 'jsonSchema7', 'draft-2020-12') to a zod-to-json-schema target. If the target string is not in TARGET_MAP, it throws listing the supported targets, rather than emitting a schema for an unknown dialect.
Source
Thrown at packages/schema-compat/src/standard-schema/adapters/zod-v3.ts:40
* Converts a Zod schema to JSON Schema using the specified target format.
*
* @param zodSchema - The Zod schema to convert
* @param options - Standard Schema JSON options including the target format
* @returns The JSON Schema representation
* @throws Error if the target format is not supported
*
* @internal
*/
function convertToJsonSchema<T extends ZodType<any, ZodTypeDef, any>>(
zodSchema: T,
options: StandardJSONSchemaV1.Options,
): Record<string, unknown> {
const target = TARGET_MAP[options.target];
if (!target) {
// For unknown targets, try to use jsonSchema7 as fallback or throw
const supportedTargets = Object.keys(TARGET_MAP);
throw new Error(
`Unsupported JSON Schema target: "${options.target}". ` + `Supported targets are: ${supportedTargets.join(', ')}`,
);
}
const jsonSchema = zodToJsonSchemaOriginal(zodSchema, {
$refStrategy: 'none',
target,
override: (def: any) => {
// Mark z.date() with x-date for downstream string→Date conversion.
// Zod v3 has no z.coerce.date(), so all dates are strict.
if (def.typeName === 'ZodDate') {
return { type: 'string', format: 'date-time', 'x-date': true };
}
return ignoreOverride;
},
});
traverse(jsonSchema, {View on GitHub (pinned to 75dd419e61)
Solutions
- Use one of the targets listed in the error message (e.g. the adapter's canonical 'jsonSchema7').
- Check the TARGET_MAP keys in packages/schema-compat/src/standard-schema/adapters/zod-v3.ts for exact spellings.
- Normalize/whitelist user- or config-supplied targets before calling the converter.
- If you truly need an unsupported dialect, convert to the supported target and post-transform the schema.
Example fix
// before
convertToJsonSchema(schema, { target: 'draft-07' });
// after
convertToJsonSchema(schema, { target: 'jsonSchema7' }); Defensive patterns
Strategy: validation
Validate before calling
const SUPPORTED_TARGETS = ['jsonSchema7', 'jsonSchema2019-09', 'openApi3_0']; // keep in sync with TARGET_MAP
function assertValidTarget(target: string) {
if (!SUPPORTED_TARGETS.includes(target)) throw new TypeError(`Unsupported JSON Schema target: ${target}`);
} Type guard
type SupportedTarget = 'jsonSchema7' | 'jsonSchema2019-09' | 'openApi3_0';
function isSupportedTarget(t: string): t is SupportedTarget {
return ['jsonSchema7', 'jsonSchema2019-09', 'openApi3_0'].includes(t);
} Try / catch
try {
js = convertToJsonSchema(schema, { target });
} catch (e) {
if ((e as Error).message.includes('Unsupported JSON Schema target')) {
js = convertToJsonSchema(schema, { target: 'jsonSchema7' });
} else throw e;
} Prevention
- Type target as a union of supported literal strings.
- Keep target strings centralized in one constant, not inlined at call sites.
- Whitelist/normalize external config targets before conversion.
When it happens
Trigger: Calling jsonSchemaConverter / convertToJsonSchema with an options.target value not in the adapter's TARGET_MAP — e.g. a typo like 'jsonschema7', a draft name like 'draft-07', or a target valid for another library but not this one.
Common situations: Copy-pasting target strings from other JSON-schema tooling; version changes where a target was renamed; config files where the target is user-supplied and unvalidated.
Related errors
- OBSERVABILITY_INVALID_CONFIG
- OBSERVABILITY_INVALID_INSTANCE_CONFIG
- We could not convert the schema to a JSONSchema
- ${message}
- Invalid parameters for ${strategy} strategy: '${keys}' not s
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/8084aa722a67f91c.
Report an issue: GitHub.