Module: Legion::LLM::Call::StructuredOutput
- Extended by:
- Legion::Logging::Helper
- Defined in:
- lib/legion/llm/call/structured_output.rb
Overview
Structured (JSON-schema) generation. SSOT v3: every provider-backed turn
flows through the canonical Request -> Executor/RoutingSession path via
Prompt.dispatch. The json_schema response_format makes
Router::RequiredCapabilities derive the structured_output capability, so
the router selects a lane whose offering advertises it — there is no
hard-coded capable-model list, no model/provider default, and no dead
resolve_chain. Callers forward explicit provider/model or none.
Class Method Summary collapse
Class Method Details
.generate(messages:, schema:, model: nil, provider: nil, **opts) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/legion/llm/call/structured_output.rb', line 18 def generate(messages:, schema:, model: nil, provider: nil, **opts) result = run_structured_chat(messages: , schema: schema, model: model, provider: provider, **opts.except(:attempt)) content = strip_markdown_fences(response_content(result)) raw_model = response_model(result) parsed = Legion::JSON.load(content) log.info "[llm][structured_output] model=#{raw_model || model} provider=#{provider} valid=true" { data: parsed, raw: content, model: raw_model, valid: true } rescue Legion::JSON::ParseError => e log.warn "[llm][structured_output] model=#{model} provider=#{provider} parse_error=#{e.}" handle_parse_error(e, , schema, model, provider, result, **opts) end |