Skip to documentation
Documentation navigation

Documentation navigation

Documentation / guides

Feature validation

Validate request feature combinations and inspect bounded typed errors.

developer

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

  1. TransientMessages must fall within the message slice.
  2. ToolChoice must be a value built by ToolAuto, ToolRequired, or ToolNamed; a required choice needs at least one tool, and a named choice must name a declared tool.
  3. If the message thread contains images, Model.Caps.AcceptsImages must be true. The scan descends into ToolResultBlock.Content.
  4. If Output is nil, validation ends successfully here.
  5. The output schema is validated.
  6. Tool names must be unique and must not use StructuredOutputToolName.
  7. 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

ErrorWhen
*StructuredOutputConflictErrorInvalid tool choice, duplicate name, or reserved output tool
*ImageInputUnsupportedErrorImage present but model lacks AcceptsImages
*SchemaValidationErrorOutputSchema is malformed or outside the portable subset
*StructuredOutputUnsupportedErrorModel lacks native structured output
*StructuredOutputWithToolsUnsupportedErrorModel lacks structured output with ordinary tools

Errors intentionally carry bounded classifications, not raw schema or tool payloads.

Proof

Related: Structured output requests, Model capabilities.

← back to documentation