{"record":{"id":"a6406e3797e95c6a","repo":"siyuan-note/siyuan","slug":"invalid-output-schema-w","errorCode":null,"errorMessage":"invalid output schema: %w","messagePattern":"invalid output schema: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/mcp/tools/validation.go","lineNumber":59,"sourceCode":"\tinput           *jsonschema.Resolved\n\toutput          *jsonschema.Resolved\n\tvalidationSlots chan struct{}\n}\n\nfunc CompileToolValidator(tool *Tool) (*ToolValidator, error) {\n\tif tool == nil {\n\t\treturn nil, fmt.Errorf(\"tool is nil\")\n\t}\n\n\tinput, err := resolveToolSchema(tool.InputSchema, true)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"invalid input schema: %w\", err)\n\t}\n\n\tvar output *jsonschema.Resolved\n\tif tool.OutputSchema != nil {\n\t\tif output, err = resolveToolSchema(*tool.OutputSchema, false); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid output schema: %w\", err)\n\t\t}\n\t}\n\treturn &ToolValidator{\n\t\tinput:           input,\n\t\toutput:          output,\n\t\tvalidationSlots: make(chan struct{}, toolValidationConcurrency),\n\t}, nil\n}\n\nfunc resolveToolSchema(schema ToolSchema, requireObject bool) (*jsonschema.Resolved, error) {\n\tif schema.Raw != nil {\n\t\tif err := validateJSONComplexity(schema.Raw, maxToolSchemaDepth, maxToolSchemaNodes); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\tdata, err := json.Marshal(schema)\n\tif err != nil {\n\t\treturn nil, err","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/mcp/tools/validation.go#L41-L77","documentation":"When a Tool declares an OutputSchema, CompileToolValidator resolves it like the input schema and wraps failures with \"invalid output schema: %w\". The same rules apply: valid JSON Schema, within the 1 MiB / depth / node limits. This error means the tool's declared output schema cannot be compiled into a validator.","triggerScenarios":"Setting Tool.OutputSchema to a malformed schema, an oversized (>1 MiB) schema, an over-complex schema, or one that fails jsonschema parsing during SetTool/buildCapabilitySet.","commonSituations":"Adding structured tool output support with a hand-crafted output schema containing invalid keywords; auto-generated response schemas exceeding limits; typo'd type names in the output schema.","solutions":["Inspect the wrapped cause for the exact failure.","Fix invalid keywords/types in the output schema.","Simplify or split the schema to fit size/depth/node limits.","Set OutputSchema to nil if structured output is not actually needed."],"exampleFix":"// before\nOutputSchema: &map[string]any{\"type\": \"objet\"}\n// after\nOutputSchema: &map[string]any{\"type\": \"object\", \"properties\": map[string]any{...}}","handlingStrategy":"validation","validationCode":"if out != nil {\n    data, _ := json.Marshal(*out)\n    if len(data) > 1<<20 {\n        return errors.New(\"output schema exceeds 1MiB\")\n    }\n}","typeGuard":"func hasOutputSchema(t *tools.Tool) bool { return t != nil && t.OutputSchema != nil }","tryCatchPattern":"err := tools.SetTool(name, def)\nif err != nil && strings.Contains(err.Error(), \"invalid output schema\") {\n    log.Printf(\"tool %s: fix OutputSchema: %v\", name, err)\n    def.OutputSchema = nil // degrade gracefully, retry\n    err = tools.SetTool(name, def)\n}","preventionTips":["Test-compile every output schema in unit tests","Mirror output schemas on the tool's response structs to keep them in sync","Keep output schemas minimal; describe only fields clients consume"],"tags":["go","json-schema","structured-output"],"backgroundTag":"schema-validation-failed","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}