Add structured output support with Generate[T] and GenerateWith[T]
All checks were successful
CI / Lint (push) Successful in 9m35s
CI / V2 Module (push) Successful in 11m43s
CI / Root Module (push) Successful in 11m53s

Generic functions that use the "hidden tool" technique to force models
to return structured JSON matching a Go struct's schema, replacing the
verbose "tool as structured output" pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-07 22:36:33 -05:00
parent 6a7eeef619
commit be572a76f4
3 changed files with 298 additions and 0 deletions

View File

@@ -14,4 +14,7 @@ var (
// ErrStreamClosed is returned when trying to read from a closed stream.
ErrStreamClosed = errors.New("stream closed")
// ErrNoStructuredOutput is returned when the model did not return a structured output tool call.
ErrNoStructuredOutput = errors.New("model did not return structured output")
)