siyuan-note/siyuan · error
invalid output schema
Error message
invalid output schema: %w
What it means
CompileToolValidator optionally compiles a tool's OutputSchema into a resolved validator used by ValidateOutputContext. If the output schema fails resolveToolSchema — invalid JSON Schema, unresolvable references, or complexity limits — registration fails wrapped as 'invalid output schema'. Unlike input schemas, the root type is not required to be "object" (requireObject=false).
Solutions
- Inspect the wrapped inner error for the precise failure (resolve error vs complexity limit).
- Validate the OutputSchema as standalone JSON Schema (e.g. with a linter) before registering.
- Fix broken $ref/$defs references; jsonschema.Resolve(nil) is called with no base URI, so relative refs must resolve within the document.
- Shrink or flatten the schema if it exceeds 1 MiB / 64 depth / 16384 nodes.
- Drop OutputSchema (return nil) if the tool does not actually guarantee structured content, since defining it makes structured content mandatory at validation time.
Example fix
// before
OutputSchema: &ToolSchema{Type: "object", Properties: map[string]Property{"items": {Type: "array", Ref: "#/definitions/Item"}}} // missing definitions
// after
OutputSchema: &ToolSchema{Type: "object", Definitions: map[string]any{"Item": itemSchema}, Properties: map[string]Property{"items": {Type: "array", Ref: "#/definitions/Item"}}} Defensive patterns
Strategy: validation
Validate before calling
function assertValidOutputSchema(schema) {
const s = JSON.stringify(schema);
if (s.length > 1048576) throw new Error("output schema exceeds 1 MiB");
for (const ref of s.match(/"\$ref":"([^"]+)"/g) ?? []) {
if (!schema["$defs"] && !schema.definitions) throw new Error("dangling $ref: " + ref);
}
} Type guard
function declaresResolvableOutputSchema(t) {
return t?.OutputSchema == null || typeof t.OutputSchema === "object";
} Try / catch
validator, err := CompileToolValidator(tool)
if err != nil {
if strings.HasPrefix(err.Error(), "invalid output schema:") {
return fmt.Errorf("tool %s output schema rejected: %w", tool.Name, err)
}
return err
} Prevention
- Validate OutputSchema standalone as JSON Schema before attaching it to a tool.
- Define all $defs in the same schema document; Resolve is called with a nil base URI.
- Keep output schemas small and flat — 1 MiB / 64 depth / 16384 node budgets apply.
- Only declare OutputSchema if the handler always returns structured content.
When it happens
Trigger: Registering a tool with tool.OutputSchema != nil whose schema fails to resolve: broken $ref, invalid JSON Schema keywords, JSON marshal/unmarshal error, serialized size over 1 MiB, depth over 64, or more than 16384 nodes.
Common situations: Tools declaring structured output with a mistyped or recursive schema without proper $defs, copy-pasted schemas from another validator dialect with unsupported keywords, or auto-generated output schemas that exceed the size/complexity budget.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- invalid input schema
- property : duplicate x-mcp-header value
- property : x-mcp-header can only be applied to primitive…
- property : x-mcp-header must be a non-empty string
- property : x-mcp-header value is not a valid HTTP field name
AI-assisted analysis of siyuan-note/siyuan@9f775e8a12 (2026-09-19).
Data as JSON: /api/errors/a6406e3797e95c6a.
Report an issue: GitHub.
Appendix: source
Thrown at kernel/mcp/tools/validation.go:59
input *jsonschema.Resolved
output *jsonschema.Resolved
validationSlots chan struct{}
}
func CompileToolValidator(tool *Tool) (*ToolValidator, error) {
if tool == nil {
return nil, fmt.Errorf("tool is nil")
}
input, err := resolveToolSchema(tool.InputSchema, true)
if err != nil {
return nil, fmt.Errorf("invalid input schema: %w", err)
}
var output *jsonschema.Resolved
if tool.OutputSchema != nil {
if output, err = resolveToolSchema(*tool.OutputSchema, false); err != nil {
return nil, fmt.Errorf("invalid output schema: %w", err)
}
}
return &ToolValidator{
input: input,
output: output,
validationSlots: make(chan struct{}, toolValidationConcurrency),
}, nil
}
func resolveToolSchema(schema ToolSchema, requireObject bool) (*jsonschema.Resolved, error) {
if schema.Raw != nil {
if err := validateJSONComplexity(schema.Raw, maxToolSchemaDepth, maxToolSchemaNodes); err != nil {
return nil, err
}
}
data, err := json.Marshal(schema)
if err != nil {
return nil, errView on GitHub (pinned to 9f775e8a12)