Implementation:Mistralai Client python Tool And Function
| Knowledge Sources | |
|---|---|
| Domains | Function_Calling, API_Design |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Concrete tool for defining function schemas that language models can invoke provided by the mistralai SDK's Tool and Function models.
Description
The Tool and Function Pydantic models define callable tools for the Mistral chat API. Function specifies the function's name, description, parameters (as a JSON Schema dict), and optionally strict mode for exact schema matching. Tool wraps a Function with a type field (always "function"). A list of Tool objects is passed to chat.complete(tools=...) to enable function calling.
Usage
Import Tool and Function when setting up function calling. Create one Tool per callable function with a clear description and typed parameter schema. Pass the list to chat.complete(tools=[...]) or chat.stream(tools=[...]).
Code Reference
Source Location
- Repository: client-python
- File: src/mistralai/client/models/tool.py (L1-20), src/mistralai/client/models/function.py (L1-24)
Signature
class Function(BaseModel):
name: str
description: Optional[str] = None
parameters: Dict[str, Any]
strict: Optional[bool] = None
class Tool(BaseModel):
function: Function
type: Optional[ToolTypes] = None # Defaults to "function"
Import
from mistralai.models import Tool, Function
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| function.name | str | Yes | Function name for model to call |
| function.description | Optional[str] | No | Natural language description of function purpose |
| function.parameters | Dict[str, Any] | Yes | JSON Schema describing function parameters |
| function.strict | Optional[bool] | No | Enforce strict schema matching |
Outputs
| Name | Type | Description |
|---|---|---|
| Tool object | Tool | Validated tool definition ready for chat.complete(tools=[...]) |
Usage Examples
Define a Weather Lookup Tool
from mistralai.models import Tool, Function
weather_tool = Tool(
function=Function(
name="get_weather",
description="Get the current weather for a given city.",
parameters={
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "City name, e.g., 'Paris'"
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit"
}
},
"required": ["city"]
},
)
)
# Pass to chat.complete
response = client.chat.complete(
model="mistral-large-latest",
messages=[UserMessage(content="What's the weather in Paris?")],
tools=[weather_tool],
)