Principle:Mistralai Client python Tool Call Parsing
| Knowledge Sources | |
|---|---|
| Domains | Function_Calling, API_Design |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
A response parsing pattern that detects and extracts structured function call instructions from a language model's response.
Description
Tool Call Parsing is the process of inspecting a chat completion response to determine if the model has requested to call one or more functions. When the model decides a tool is needed, it populates tool_calls on the assistant message instead of (or in addition to) generating text content. Each tool call contains a unique id, the function.name to invoke, and function.arguments as a JSON string that must be parsed to extract the actual arguments.
Usage
Use this principle after receiving a chat completion response when tools were provided. Check response.choices[0].message.tool_calls to detect if the model wants to call functions. If present, parse each tool call and dispatch to the appropriate function.
Theoretical Basis
Tool call detection follows a branching response pattern:
- If finish_reason is "tool_calls", the model wants to call tools
- Each ToolCall has an id (for result mapping) and function details
- function.arguments is a JSON string that must be deserialized
- Multiple tool calls may be present if parallel_tool_calls was enabled