Project Quarry
Python framework and DSL for detecting threats and behavior patterns in AI agent conversations using compiled rules.
At a Glance
About Project Quarry
Project Quarry is a Python framework from the cisco-ai-defense organization for detecting threats and behavior patterns in agent conversations. Rules are written in a DSL over messages, tool calls, tool results, and event order, and can optionally call a configured model adapter. The project is in alpha, and its DSL syntax may change before v1.0.0.
What It Is
Quarry is a detection DSL and engine for AI agents. Rules live in .rule files, each containing one named rule with optional metadata, strings, variables, and parameters blocks plus a required condition. When rules are loaded, Quarry parses, validates, links, and compiles each one to a symbolic finite-state automaton, and rules that cannot compile fail at load time. A scan runs the compiled program over an OpenAI-shaped conversation supplied as JSON with a messages array.
How Detection Works
Rules can use text, RE2 regular expressions, structured-field, and tool use checks. Multi-turn flow rules support captures, counts, and typed policy parameters. When local checks are not enough, a rule can use a configured model for scoring, classification, completion, token counting, and spans. Results include witness evidence, explain output, and typed collections for supported rules. Explicit input, compile, time, and model-call limits can be set.
Using It
Quarry supports Python 3.11 through 3.13 and is installed from source with uv. It exposes sync and async Python APIs, including QuarryGuard, DSLScanner, and compile_policy, and a CLI with human, JSON, and CSV output. The CLI exits 0 for a clean scan, 1 for a match, and 2 for an invalid or incomplete scan. The repository also documents an agent plugin for Codex, Claude Code, and MCP hosts, and ships synthetic examples that run without model credentials.
Community Discussions
Be the first to start a conversation about Project Quarry
Share your experience with Project Quarry, ask questions, or help others learn from your insights.
Pricing
Open Source
Self-hosted Python framework under the Apache 2.0 license (alpha release).
- Apache License 2.0 (OSI-approved)
- Text, regex (RE2), structured-field, and tool use checks
- Multi-turn flow rules, captures, counts, and typed policy parameters
- Sync and async Python APIs, plus human, JSON, and CSV CLI output
- Optional model adapters (built-in providers require the inference extra; model provider costs are external)
Capabilities
Key Features
- Detection DSL compiled to symbolic finite-state automata
- Text, RE2 regex, structured-field, and tool use checks
- Multi-turn flow rules, captures, counts, and typed policy parameters
- Optional model scoring, classification, completion, token counting, and spans
- Witness evidence and explain output
- Sync and async Python APIs
- Human, JSON, and CSV CLI output
- Explicit input, compile, time, and model-call limits
- Agent plugin for Codex, Claude Code, and MCP hosts
