Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Mistralai Client python Tool Call Parsing

From Leeroopedia
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:

  1. If finish_reason is "tool_calls", the model wants to call tools
  2. Each ToolCall has an id (for result mapping) and function details
  3. function.arguments is a JSON string that must be deserialized
  4. Multiple tool calls may be present if parallel_tool_calls was enabled

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment