fn sanitize_tool_calls_for_history(calls: &[Value]) -> Vec<Value>Expand description
Return a copy of calls safe to store in the chat history that gets re-sent
on the next request.
OpenAI-compatible endpoints reject a tool_call whose function.arguments is
not valid JSON. A model can emit a truncated/garbled call (e.g. an
unterminated string when its output is cut off), and re-sending that verbatim
makes the next request fail with a provider 400 - turning a recoverable
tool error into a dead end for the whole turn. Replace any unparseable
arguments with {} so the history stays well-formed. The original
(malformed) call is still executed, so the model gets the informative
“arguments are not valid JSON” tool result and can retry.