fix: force tool calls when outputFormat is json_schema

When structured output is requested, the model must call the
StructuredOutput tool instead of responding with plain text.

Changes:
- Add toolChoice parameter to LLM.StreamInput
- Pass toolChoice: "required" to streamText when outputFormat is json_schema
- This forces the model to call a tool, ensuring structured output is captured
pull/8161/head
Kyle Mistele 2026-01-12 23:05:43 -08:00
parent 34f9feb12d
commit 0e8f7694ed
2 changed files with 3 additions and 0 deletions

View File

@ -28,6 +28,7 @@ export namespace LLM {
small?: boolean
tools: Record<string, Tool>
retries?: number
toolChoice?: "auto" | "required" | "none"
}
export type StreamOutput = StreamTextResult<ToolSet, unknown>
@ -146,6 +147,7 @@ export namespace LLM {
providerOptions: ProviderTransform.providerOptions(input.model, params.options),
activeTools: Object.keys(tools).filter((x) => x !== "invalid"),
tools,
toolChoice: input.toolChoice,
maxOutputTokens,
abortSignal: input.abort,
headers: {

View File

@ -573,6 +573,7 @@ export namespace SessionPrompt {
],
tools,
model,
toolChoice: outputFormat.type === "json_schema" ? "required" : undefined,
})
// Handle structured output logic