Documentation
¶
Overview ¶
Package outputvalidation provides a pure, self-contained validator that checks a tool's structured output against its declared JSON Schema (draft 2020-12).
Contract:
- Imports only stdlib, go.uber.org/zap, and github.com/santhosh-tekuri/jsonschema/v6.
- MUST NOT import internal/server, internal/config, internal/storage, or mcp-go.
- Safe for concurrent use (sync.Map cache, no shared mutable state).
- Never blocks on the proxy's inability to compile a schema (FR-A9).
- Never mutates the structured value passed to Validate.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Outcome ¶
type Outcome int
Outcome indicates whether a structured output conforms to its schema.
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator validates a tool's structured output against its declared JSON Schema, applying byte-size and nesting-depth guards first. Safe for concurrent use.
func New ¶
New creates a new Validator.
- maxBytes <= 0 disables the byte-size guard.
- maxDepth <= 0 disables the nesting-depth guard.
- logger may be nil; if nil, zap.NewNop() is used.
func (*Validator) Validate ¶
Validate checks structured against schemaJSON for the tool identified by toolKey.
Decision tree (in order):
- schemaJSON == "" → OutcomePass (FR-A7: no schema declared, no-op)
- structured == nil → OutcomePass (FR-A8: nothing to validate)
- Guards (byte size, nesting depth) — on breach, return OutcomeViolate immediately
- Schema compilation (cached) — uncompilable schemas log once and return OutcomePass (FR-A9)
- Schema validation — return OutcomeViolate on mismatch, OutcomePass on success
Validate MUST NOT mutate structured.
type Verdict ¶
type Verdict struct {
Outcome Outcome
Reason string // human-readable violation detail; empty on pass
GuardHit string // "" | "max_bytes" | "max_depth"
}
Verdict is the result returned by Validator.Validate. It is never persisted; it is purely transient.
func (Verdict) IsViolation ¶
IsViolation reports whether the verdict represents a violation.