Skip to main content

finalize_tool_call

Function finalize_tool_call 

Source
fn finalize_tool_call(
    codecs: &[BodyCodec],
    body: &str,
    out: &mut ParserOutput,
    mint_id: impl FnMut() -> String,
)
Expand description

Parse the accumulated tool-call body and push the resulting ToolCalls (or a NormalizationError) onto out.

The spec’s codecs are tried in order; the first codec that decodes the body wins. The built-in Qwen spec lists JSON before inner XML: JSON is the historical Qwen format and is unambiguous, while the XML form is the documented fallback for Qwen3 chat templates that emit nested function/parameter markup inside the envelope.

On failure, the error kind reflects which codec was plausibly in play: a body that looks like it opened the inner-XML codec (<function=) — when that codec is enabled — reports NormalizationErrorKind::MalformedFunctionXml instead of the generic JSON failure, since the two codecs fail for unrelated reasons and a log reader should not have to guess which one was attempted.