Documentation / guides
Feature validation
Validate request feature combinations and inspect bounded typed errors.
ValidateRequestFeatures is the shared pre-codec gate for optional request features. It checks combinations that provider codecs should not have to rediscover, while leaving dialect-specific validation to the codec.
Validation order
TransientMessagesmust fall within the message slice.ToolChoicemust be a value built byToolAuto,ToolRequired, orToolNamed; a required choice needs at least one tool, and a named choice must name a declared tool.- If the message thread contains images,
Model.Caps.AcceptsImagesmust be true. The scan descends intoToolResultBlock.Content. - If
Outputis nil, validation ends successfully here. - The output schema is validated.
- Tool names must be unique and must not use
StructuredOutputToolName. - The model must advertise structured output, and structured output with tools when tools are present.
err := inference.ValidateRequestFeatures(request)
var unsupported *inference.StructuredOutputUnsupportedError
if errors.As(err, &unsupported) {
// Present a model-capability message without exposing schema bytes.
log.Printf("model cannot produce structured output: %s", unsupported.Model)
}
Typed failures
| Error | When |
|---|---|
*StructuredOutputConflictError | Invalid tool choice, duplicate name, or reserved output tool |
*ImageInputUnsupportedError | Image present but model lacks AcceptsImages |
*SchemaValidationError | OutputSchema is malformed or outside the portable subset |
*StructuredOutputUnsupportedError | Model lacks native structured output |
*StructuredOutputWithToolsUnsupportedError | Model lacks structured output with ordinary tools |
Errors intentionally carry bounded classifications, not raw schema or tool payloads.
Proof
- Source:
inference/client.go,inference/structured_errors.go - Tests:
inference/client_test.gocovers ordering, nested images, duplicates, reserved names, and bounded diagnostics.
Related: Structured output requests, Model capabilities.