{"record":{"id":"3ad71169dcb065e7","repo":"can1357/oh-my-pi","slug":"yield-parameters-schema-is-invalid","errorCode":null,"errorMessage":"yield parameters schema is invalid","messagePattern":"yield parameters schema is invalid","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/coding-agent/src/tools/yield.ts","lineNumber":340,"sourceCode":"\t\t\tlet dataSchema: Record<string, unknown>;\n\t\t\tif (sanitizedSchema !== undefined) {\n\t\t\t\tconst resolved = dereferenceJsonSchema({\n\t\t\t\t\t...sanitizedSchema,\n\t\t\t\t\tdescription: schemaDescription,\n\t\t\t\t}) as Record<string, unknown>;\n\t\t\t\tif (hasUnresolvedRefs(resolved)) {\n\t\t\t\t\tthrow new Error(\"schema contains unresolved $ref after dereferencing\");\n\t\t\t\t}\n\t\t\t\tdataSchema = withSectionVariants(resolved);\n\t\t\t} else {\n\t\t\t\tthis.strict = false;\n\t\t\t\tdataSchema = looseRecordSchema(\n\t\t\t\t\tschemaError ? schemaDescription : \"Structured JSON output (no schema specified)\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tparameters = wrapYieldParameters(dataSchema);\n\t\t\tJSON.stringify(parameters);\n\t\t\tif (!isValidJsonSchema(parameters)) throw new Error(\"yield parameters schema is invalid\");\n\t\t} catch (err) {\n\t\t\tconst errorMsg = err instanceof Error ? err.message : String(err);\n\t\t\tparameters = wrapYieldParameters(\n\t\t\t\tlooseRecordSchema(`Structured JSON output (schema processing failed: ${errorMsg})`),\n\t\t\t);\n\t\t\tvalidate = undefined;\n\t\t\tthis.strict = false;\n\t\t}\n\n\t\tthis.#validate = validate;\n\t\tthis.#validateSection = validateSection;\n\t\tthis.#rejectUnknownSections = rejectUnknownSections;\n\t\tthis.#knownSectionLabels = knownSectionLabels;\n\t\tthis.#isKnownSection = isKnownSection;\n\t\tthis.description = prompt.render(yieldDescription, { hasOutputSchema: validate !== undefined });\n\t\tthis.parameters = parameters;\n\t}\n","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/yield.ts#L322-L358","documentation":"After wrapping the (possibly sanitized) data schema, YieldTool validates the final `parameters` schema and stringifies it. If isValidJsonSchema fails — or any prior step in the try block throws — this Error is caught by the surrounding handler, which then falls back to a loose record schema embedding the error message, so structured output degrades gracefully rather than crashing.","triggerScenarios":"A wrapped yield parameters schema that violates JSON Schema constraints (e.g. invalid `type` values, conflicting keywords like `required` referencing nonexistent properties, unsupported combinations introduced by withSectionVariants/wrapYieldParameters).","commonSituations":"Schemas with provider-unsupported keywords or malformed constraints; deeply nested schemas that sanitization mutates into invalid form; custom validators flagging fields the provider would reject.","solutions":["Fix the supplied schema to be a valid JSON Schema (correct types, required keys referencing existing properties).","Inspect the fallback message in the tool parameters — it embeds the original error text (`schema processing failed: ...`).","Simplify the schema (fewer exotic keywords) and retry.","Omit the schema to use the default loose record schema.","null"],"exampleFix":"// before\nyield({ schema: { type: \"object\", properties: { x: { type: \"integer\" } }, required: [\"x\",\"y\"] } })\n// after\nyield({ schema: { type: \"object\", properties: { x: { type: \"integer\" } }, required: [\"x\"] } })","handlingStrategy":"try-catch","validationCode":"// pre-validate with the same validator family before constructing\nif (!isValidJsonSchema(candidateSchema)) console.error(\"invalid schema\", JSON.stringify(candidateSchema));","typeGuard":"function isValidJsonSchema(s: unknown): boolean { /* validate against JSON Schema meta-schema */ return validateMetaSchema(s); }","tryCatchPattern":"try { const t = new YieldTool({ schema }); } catch (err) { console.warn(\"falling back to loose schema:\", err.message); const t = new YieldTool({}); // loose record schema }","preventionTips":["Keep schemas simple: standard types, valid `required` lists, no exotic keywords.","Test schema construction in CI before relying on structured output.","Read the fallback message (it embeds the original failure reason).","Run schema sanitization/dereferencing before passing custom schemas."],"tags":["json-schema","yield","validation"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}