Mistral AI

Mistral AI

Gate Mistral function calls and tool invocations behind a human approval checkpoint using the Cheqpoint SDK. Works with mistralai Python and JS/TS clients.

How it works

Mistral supports function calling via its chat completions API. When Mistral returns a tool call in its response, your application is responsible for executing it. Cheqpoint intercepts that execution — submitting an approval request and blocking until a human decides before any action is taken.

Prerequisites

  • Python 3.9+ or Node.js environment.
  • mistralai SDK and a Mistral API key.
  • Cheqpoint Connection Key.

Steps

  1. Define your tools as Mistral function definitions.
  2. Send the chat request and check if the response contains tool_calls in the message.
  3. For each tool call, submit a Cheqpoint approval request with the tool name and arguments before executing.
  4. If approved, dispatch the tool function and return the result to the model.
  5. If rejected, return an error tool result so Mistral can explain the block to the user.

Installation

bash
pip install cheqpoint mistralai

Sample request payload

json
{
  "action": "update_account_email",
  "summary": "Mistral requesting email update for account acc_9921",
  "details": {
    "accountId": "acc_9921",
    "currentEmail": "user@old.com",
    "newEmail": "user@new.com"
  }
}

Sample Cheqpoint response

json
{
  "status": "approved",
  "modifiedDetails": null,
  "decisionNote": "Identity verified. Email update approved."
}
import os, json
from mistralai import Mistral
from cheqpoint import CheqpointClient

client = Mistral(api_key=os.environ["MISTRAL_API_KEY"])
cheq = CheqpointClient(api_key=os.environ["CQ_API_KEY"])

tools = [{
    "type": "function",
    "function": {
        "name": "update_account_email",
        "description": "Update the email address for a given account",
        "parameters": {
            "type": "object",
            "properties": {
                "accountId": {"type": "string"},
                "newEmail": {"type": "string"},
            },
            "required": ["accountId", "newEmail"],
        },
    },
}]

messages = [{"role": "user", "content": "Change the email for account acc_9921 to user@new.com"}]
response = client.chat.complete(model="mistral-large-latest", messages=messages, tools=tools)

message = response.choices[0].message
if message.tool_calls:
    for tool_call in message.tool_calls:
        fn_name = tool_call.function.name
        fn_args = json.loads(tool_call.function.arguments)

        # Gate behind Cheqpoint
        approval = cheq.request_sync(
            action=fn_name,
            summary=f"Mistral requesting {fn_name}",
            details=fn_args,
            timeout_ms=30_000,
        )

        if approval["status"] == "approved":
            effective = approval.get("modifiedDetails") or fn_args
            result = dispatch_tool(fn_name, effective)
            tool_result = str(result)
        else:
            tool_result = f"Action rejected: {approval.get('decisionNote', 'blocked by reviewer')}"

        # Return result to Mistral
        messages += [
            message,
            {"role": "tool", "tool_call_id": tool_call.id, "content": tool_result},
        ]
        final = client.chat.complete(model="mistral-large-latest", messages=messages)
        print(final.choices[0].message.content)

Get your Connection Key at cheqpoint.co/signup.