Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

mistralai-agentic-security

` markers, so regeneration keeps this text.

Examples follow agentic_safety/docs/. See clients/README.md. -->

Agentic Security checks what your agents read and write against your rules, and acts on what they catch: it redacts, blocks, asks a human, or unplugs a tool.

This package has two parts:

  • Guardrails, a hook for Mistral Agents that applies your policies to every turn and tool call.
  • AgenticSafetyClient, a typed client to manage rules, policies and alerts as code.

Install

uv add "mistralai-agentic-security[guardrails]" mistralai-agents

The guardrails extra needs Python 3.12 to 3.14. The client alone (uv add mistralai-agentic-security) runs on Python 3.10 and later.

Both read your Mistral API key from the environment:

export MISTRAL_API_KEY="<your api key>"

Protect an agent

Create a policy in Mistral Studio, then pass its tag to Guardrails:

import asyncio

from mistral.agentic_safety.guardrails import Guardrails
from mistralai.agents import agents


async def main() -> None:
    agent = agents.Agent(
        model="mistral-large-4-0",
        instructions="Answer in one sentence.",
        guardrails=[Guardrails(tags=["policy_id:01a1c12f-c1e6-7663-8d73-846c1833ea32"])],
    )

    result = await agent.run("Reply to: Bob was charged twice on card 4539 1488 0343 6467. He wants a refund.")
    print(result.text)


asyncio.run(main())
Hi Bob, thanks for flagging this, we've confirmed the duplicate charge and sent a refund.

With a policy that redacts card numbers, the model drafts the reply without ever seeing the card number. A turn that a rule blocks stops before the model runs.

Manage rules as code

A rule says when to check (hooks), what to look for (scanners), and what to do (cases). A policy groups rules and turns them on.

import asyncio

from mistral.agentic_safety import AgenticSafetyClient, models


async def main() -> None:
    client = AgenticSafetyClient()

    rule = await client.rules.create_rule_async(
        name="Redact card numbers",
        hooks=[models.Hook(name="pre_agent_turn", ctx_last_user=True)],
        scanners=[
            models.PatternScanner(
                name="pii",
                patterns=[models.PatternEntry(label="credit_card", regex=r"\b(?:\d[ -]?){13,16}\b")],
            )
        ],
        cases=[
            models.Case(
                name="credit card",
                condition=models.Condition(
                    clauses=[
                        models.Comparison(
                            op=models.Op.GREATER_THAN_,
                            left=models.EvidenceOperand(scanner="pii", label="credit_card"),
                            right=models.NumberOperand(value=0),
                        )
                    ]
                ),
                verdict=models.Verdict.ALLOW,
                side_effects=[models.RedactSideEffect()],
            )
        ],
    )

    policy = await client.policies.create_policy_async(
        name="Card numbers",
        enabled=True,
        rule_ids=[rule.id],
    )
    print(policy.tags)  # pass these to Guardrails(tags=...)


asyncio.run(main())

Concepts

Hook When a rule runs: pre_agent_turn, post_agent_turn, pre_tool_call, post_tool_call. ctx_* flags pick the content it reads.
Scanner What to look for: PatternScanner, EntityScanner, ModerationScanner, SimilarityScanner, LLMScanner, or your own code with HarnessScanner. Each reports evidence named <scanner>.<label>.
Case A condition on the evidence, a verdict, and side effects.
Verdict allow, human_validation, block, terminate. The most restrictive matching case wins.
Side effect redact, unplug a tool, notify_user, or custom_callback.
Policy Groups rules, and applies to the agents that send its tags.

Configuration

Environment variable Default Used for
MISTRAL_API_KEY authentication
AGENTIC_SAFETY_SERVER_URL https://api.mistral.ai the server Guardrails calls

Guardrails fails open: if the service can't be reached, the turn goes on. Pass fail_closed_on_error=True to block it instead.

Metadata

Release files for mistralai-agentic-security 0.1.0a7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mistralai-agentic-security 0.1.0a7
File Size Uploaded Provenance Actions
mistralai_agentic_security-0.1.0a7.tar.gz 162.2 kB With provenance Details for mistralai_agentic_security-0.1.0a7.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mistralai-agentic-security 0.1.0a7
File Interpreter ABI Platform Actions
mistralai_agentic_security-0.1.0a7-py3-none-any.whl Python 3 none any Details for mistralai_agentic_security-0.1.0a7-py3-none-any.whl

Total release size: 441.1 kB

Release files / mistralai_agentic_security-0.1.0a7.tar.gz

Download URL mistralai_agentic_security-0.1.0a7.tar.gz
Size 162.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3efda43911dca6fc5181b10b3094689a38e17faf7f096f5ef5178266b717b9f2
BLAKE2b-256 checksum
How to use checksums
0c359f144641edf0633df1ea6f483aeae72e1a05b2f576857e5b641928951cde
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Release files / mistralai_agentic_security-0.1.0a7-py3-none-any.whl

Download URL mistralai_agentic_security-0.1.0a7-py3-none-any.whl
Size 278.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fa3ffdc946cb2e5eea14116cf5167242b54d60b1db7fb1b07e9bfa62c9f34194
BLAKE2b-256 checksum
How to use checksums
ac1267197f9e5cbe148ab69b246d3c9f049b67dc12127da0b325f01a7a5faa44
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

Security for mistralai-agentic-security 0.1.0a7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mistralai_agentic_security-0.1.0a7.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 19, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page