Skip to content

mistral_common.protocol.instruct.tool_calls

Function(**data)

Bases: MistralBase

Function definition for tools.

Attributes:

Name Type Description
name str

The name of the function.

description str

A description of what the function does.

parameters Dict[str, Any]

The parameters the functions accepts, described as a JSON Schema object.

Examples:

>>> function = Function(
...     name="get_current_weather",
...     description="Get the current weather in a given location",
...     parameters={
...         "type": "object",
...         "properties": {
...             "location": {
...                 "type": "string",
...                 "description": "The city and state, e.g. San Francisco, CA",
...             },
...             "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
...         },
...         "required": ["location"],
...     },
... )
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
def __init__(self, /, **data: Any) -> None:
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.
    """
    # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    __tracebackhide__ = True
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    if self is not validated_self:
        warnings.warn(
            'A custom validator is returning a value other than `self`.\n'
            "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
            'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
            stacklevel=2,
        )

FunctionCall(**data)

Bases: MistralBase

Function call.

Attributes:

Name Type Description
name str

The name of the function to call.

arguments str

The arguments to pass to the function.

Examples:

>>> function_call = FunctionCall(
...     name="get_current_weather",
...     arguments={"location": "San Francisco, CA", "unit": "celsius"},
... )
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
def __init__(self, /, **data: Any) -> None:
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.
    """
    # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    __tracebackhide__ = True
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    if self is not validated_self:
        warnings.warn(
            'A custom validator is returning a value other than `self`.\n'
            "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
            'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
            stacklevel=2,
        )

validate_arguments(v)

Convert arguments to a JSON string if they are a dictionary.

Parameters:

Name Type Description Default
v Union[str, Dict[str, Any]]

The arguments to validate.

required

Returns:

Type Description
str

The arguments as a JSON string.

Source code in src/mistral_common/protocol/instruct/tool_calls.py
@field_validator("arguments", mode="before")
def validate_arguments(cls, v: Union[str, Dict[str, Any]]) -> str:
    """Convert arguments to a JSON string if they are a dictionary.

    Args:
        v: The arguments to validate.

    Returns:
        The arguments as a JSON string.
    """
    if isinstance(v, dict):
        return json.dumps(v)
    return v

Tool(**data)

Bases: MistralBase

Tool definition.

Attributes:

Name Type Description
type ToolTypes

The type of the tool.

function Function

The function definition.

Examples:

>>> tool = Tool(
...     function=Function(
...         name="get_current_weather",
...         description="Get the current weather in a given location",
...         parameters={
...             "type": "object",
...             "properties": {
...                 "location": {
...                     "type": "string",
...                     "description": "The city and state, e.g. San Francisco, CA",
...                 },
...                 "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
...             },
...             "required": ["location"],
...         },
...     ),
... )
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
def __init__(self, /, **data: Any) -> None:
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.
    """
    # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    __tracebackhide__ = True
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    if self is not validated_self:
        warnings.warn(
            'A custom validator is returning a value other than `self`.\n'
            "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
            'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
            stacklevel=2,
        )

ToolCall(**data)

Bases: MistralBase

Tool call.

Attributes:

Name Type Description
id str

The ID of the tool call. Required for V3+ tokenization

type ToolTypes

The type of the tool call.

function FunctionCall

The function call.

Examples:

>>> tool_call = ToolCall(
...     id="call_abc123",
...     function=FunctionCall(
...         name="get_current_weather",
...         arguments={"location": "San Francisco, CA", "unit": "celsius"},
...     ),
... )
Source code in .venv/lib/python3.13/site-packages/pydantic/main.py
def __init__(self, /, **data: Any) -> None:
    """Create a new model by parsing and validating input data from keyword arguments.

    Raises [`ValidationError`][pydantic_core.ValidationError] if the input data cannot be
    validated to form a valid model.

    `self` is explicitly positional-only to allow `self` as a field name.
    """
    # `__tracebackhide__` tells pytest and some other tools to omit this function from tracebacks
    __tracebackhide__ = True
    validated_self = self.__pydantic_validator__.validate_python(data, self_instance=self)
    if self is not validated_self:
        warnings.warn(
            'A custom validator is returning a value other than `self`.\n'
            "Returning anything other than `self` from a top level model validator isn't supported when validating via `__init__`.\n"
            'See the `model_validator` docs (https://docs.pydantic.dev/latest/concepts/validators/#model-validators) for more details.',
            stacklevel=2,
        )

ToolChoice

Bases: str, Enum

Enum of tool choice types.

Attributes:

Name Type Description
auto

Automatically choose the tool.

none

Do not use any tools.

any

Use any tool.

Examples:

>>> tool_choice = ToolChoice.auto

ToolTypes

Bases: str, Enum

Enum of tool types.

Attributes:

Name Type Description
function

A function tool.

Examples:

>>> tool_type = ToolTypes.function