{"record":{"id":"7c7700f583e2ff3f","repo":"can1357/oh-my-pi","slug":"scope-does-not-match-schema-formatallvalidat","errorCode":null,"errorMessage":"${scope} does not match schema: ${formatAllValidationIssues(sectionFailure.issues)}.${retryHint}","messagePattern":"(.+?) does not match schema: (.+?)\\.(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/tools/yield.ts","lineNumber":470,"sourceCode":"\t\t\t\tconst parsed = parseJsonContainerString(data);\n\t\t\t\tif (parsed !== undefined) {\n\t\t\t\t\tconst revalidated = validateData(parsed);\n\t\t\t\t\tif (revalidated === undefined || revalidated.success) {\n\t\t\t\t\t\tdata = parsed;\n\t\t\t\t\t\tsectionFailure = revalidated;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (sectionFailure && !sectionFailure.success) {\n\t\t\t\tthis.#schemaValidationFailures++;\n\t\t\t\tif (this.#schemaValidationFailures <= MAX_SCHEMA_RETRIES) {\n\t\t\t\t\tconst remaining = MAX_SCHEMA_RETRIES - this.#schemaValidationFailures;\n\t\t\t\t\tconst retryHint =\n\t\t\t\t\t\tremaining > 0\n\t\t\t\t\t\t\t? ` Call yield again with the corrected shape — ${remaining} retry attempt(s) remain before the schema constraint is dropped.`\n\t\t\t\t\t\t\t: \" Call yield again with the corrected shape — this is the final retry before the schema constraint is dropped.\";\n\t\t\t\t\tconst scope = isIncremental ? `Section ${formatYieldLabels(yieldType as string[])}` : \"Output\";\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`${scope} does not match schema: ${formatAllValidationIssues(sectionFailure.issues)}.${retryHint}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tschemaValidationOverridden = true;\n\t\t\t}\n\t\t}\n\n\t\tthis.#emptyResultFailures = 0;\n\t\tif (status === \"success\" && isIncremental) this.#hasIncrementalSections = true;\n\t\tconst responseText =\n\t\t\tstatus === \"aborted\"\n\t\t\t\t? `Task aborted: ${errorMessage}`\n\t\t\t\t: schemaValidationOverridden\n\t\t\t\t\t? `Result submitted (schema validation overridden after ${this.#schemaValidationFailures} failed attempt(s)).`\n\t\t\t\t\t: \"Result submitted.\";\n\t\treturn {\n\t\t\tcontent: [{ type: \"text\", text: responseText }],\n\t\t\tdetails: {","sourceCodeStart":452,"sourceCodeEnd":488,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/tools/yield.ts#L452-L488","documentation":"Yielded output (terminal data or incremental section) failed JSON-schema validation against the task's declared output schema. The tool throws with all validation issues formatted, plus a retry hint showing how many in-tool schema retries remain (MAX_SCHEMA_RETRIES); after the budget is exhausted the schema constraint is dropped and the data is accepted with a schemaOverridden flag.","triggerScenarios":"Calling yield with data (or an incremental section) whose shape violates the output schema — wrong types, missing required properties, enum violations, additionalProperties violations — while a validator (#validate) is bound.","commonSituations":"The model emits strings where numbers are required, omits required fields, or nests objects differently than the schema; strict-mode schemas reject extra keys the model added; partial incremental payloads are submitted that don't yet match the section's slice of the schema.","solutions":["Read the formatted validation issues in the message and fix each listed path/type mismatch, then call yield again with the corrected shape","Validate the payload locally against the schema (e.g. with a JSON Schema validator) before submitting","Check for strict-mode pitfalls: no extra properties, exact enum values, correct required fields","If retries run out the constraint is dropped, but prefer fixing the shape — the parent may still see schemaOverridden"],"exampleFix":"// before (schema requires findings: string[])\nyield({ result: { data: { findings: \"none\" } } });\n// after\nyield({ result: { data: { findings: [\"no issues found\"] } } });","handlingStrategy":"validation","validationCode":"import { isValidJsonSchema } from '@oh-my-pi/pi-ai/utils/schema';\nconst check = validateAgainstSchema(data, outputSchema);\nif (!check.valid) throw new TypeError(check.issues.map(i => `${i.path}: ${i.message}`).join('; '));","typeGuard":"function matchesSchema(value, validate) {\n  const res = validate(value);\n  return res === undefined || res.valid === true;\n}","tryCatchPattern":"try {\n  yield({ result: { data } });\n} catch (err) {\n  if (err.message.includes('does not match schema')) {\n    const fixed = repairDataFromIssues(data, err.message); // parse issue list\n    yield({ result: { data: fixed } });\n  } else throw err;\n}","preventionTips":["Validate the payload against the output schema locally before every yield","Check strict-mode constraints: no extra properties, exact enum values, all required fields","Match primitive types exactly (number vs string) and required nesting order","Budget fixes within MAX_SCHEMA_RETRIES — the hint in the message shows remaining attempts"],"tags":["tool-call","yield","schema-validation","json-schema","subagent"],"backgroundTag":"schema-validation-failed","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}