Janus
System-level security for LLM agents via fine-grained policy enforcement on tool calls.
Janus intercepts every tool call an LLM agent makes and validates it against a security policy before execution — following the principle of least privilege. Policies are defined in JSON (or auto-generated by an LLM) and validated at runtime using JSON Schema restrictions.
Status: Alpha (v0.0.5) — APIs are stable but subject to change.
Documentation | GitHub
Table of Contents
Features
- Fine-grained policy enforcement — allow or deny tool calls based on argument-level JSON Schema conditions
- Principle of least privilege — policies restrict agents to only what is needed for a specific task
- Multiple policy sources — load from a JSON file, a Python dict, or auto-generate with an LLM
- LLM-generated policies — automatically infer minimum-privilege policies from a user's query
- Policy refinement — incrementally tighten policies as the agent discovers information during a task
- Taint tracking (IPI defence) —
TaintTracker records which untrusted sources a session has read and gates outbound/state-changing tools on them; derived automatically at the post-execution seam
- Graph-based capability surfacing — SpiceDB-backed ReBAC and a session-scalar taint gate via the optional PDE engine in
janus/policy/pde/
- Built-in tools — ready-to-use file system and command execution tools with workspace sandboxing
- Custom tools — define your own tools with
ToolDef / ToolParam; Janus guards them automatically
- 10+ LLM providers — OpenAI, Anthropic, Google Gemini, Azure OpenAI, AWS Bedrock, Ollama, vLLM, Together AI, OpenRouter
- Framework adapters — plug Janus enforcement into LangChain, Google ADK, and Claude Agent SDK (Claude Code) agents, plus a
PreToolUse hook shim (janus-hook) for the interactive Claude Code CLI
- Standalone enforcer — use
PolicyEnforcer independently in any agentic framework
- Three fallback actions — raise
PolicyViolation, call sys.exit, or prompt the user interactively
- Workspace isolation — file tools are scoped to a directory; path-traversal attempts are rejected
Installation
Requires Python ≥ 3.10. uv is the recommended package manager.
Core (standalone PolicyEnforcer + OpenAI / OpenAI-compatible providers):
uv add janus-guard
The core install has no SpiceDB/authzed or web-server dependencies, so
from janus.policy import PolicyEnforcer works on its own for use as a
lightweight tool-call gate.
With optional provider / feature extras:
uv add "janus-guard[pde]" # SpiceDB-backed ReBAC + taint tracking (PDEEnforcer)
uv add "janus-guard[server]" # Example web demo UI (FastAPI + uvicorn)
uv add "janus-guard[anthropic]" # Anthropic Claude
uv add "janus-guard[google]" # Google Gemini
uv add "janus-guard[bedrock]" # AWS Bedrock
uv add "janus-guard[langchain]" # LangChain adapter
uv add "janus-guard[adk]" # Google ADK adapter
uv add "janus-guard[claude]" # Claude Agent SDK (Claude Code) adapter
uv add "janus-guard[all]" # Everything
The Claude Code CLI adapter (janus.adapters.claude_code + the janus-hook shim) needs no extra — it ships with the core install.
For development:
uv add "janus-guard[dev]" # pytest, ruff, mypy
Install from source:
git clone https://github.com/Agentic-AI-Risk-Mitigation/Janus.git
cd janus
uv pip install -e .
Quick Start
from janus import JanusAgent
agent = JanusAgent(
model="openai/gpt-4o",
api_key="sk-...", # or set OPENAI_API_KEY env var
use_builtin_tools=True,
policy="policies.json",
system_prompt="You are a helpful coding assistant.",
)
response = agent.run("List the Python files in the project.")
print(response)
JanusAgent Parameters
| Parameter |
Type |
Default |
Description |
model |
str |
— |
Model string: "<provider>/<model-name>" (e.g. "openai/gpt-4o") |
system_prompt |
str |
"You are a helpful assistant." |
System message for the LLM |
tools |
list[ToolDef] | None |
None |
Custom tool definitions to register |
use_builtin_tools |
bool |
True |
Register built-in file and command tools |
policy |
str | Path | dict | None |
None |
Policy source (file path, dict, "generate", or None) |
policy_model |
str | None |
"gpt-4o-2024-08-06" |
Model used for LLM-based policy generation |
policy_engine |
str |
"janus" |
Enforcer engine to use ("janus" or "pde") |
agent_id |
str |
"coding_agent" |
Agent identity used for pde taint and ACL checks |
api_key |
str | None |
None |
API key (falls back to provider's env var) |
workspace |
str | Path | None |
cwd |
Root directory for file-system tools |
max_tool_iterations |
int |
10 |
Max tool-call cycles per run() call |
temperature |
float |
0.1 |
Sampling temperature |
log_level |
str | None |
"INFO" |
Logging level ("DEBUG", "INFO", "WARNING") |
JanusAgent Methods
| Method |
Description |
run(user_input) |
Run the agent and return the final text response |
clear_history() |
Reset conversation history (keeps policy and tools) |
set_policy(policy) |
Load or replace the security policy at runtime |
get_policy() |
Return the current policy dict |
save_policy(path) |
Persist the current policy to a JSON file |
allow_tools(tools) |
Unconditionally allow the listed tools (highest priority) |
block_tools(tools) |
Unconditionally block the listed tools (highest priority) |
add_tool(tool) |
Register an additional tool at runtime |
remove_tool(name) |
Unregister a tool by name |
list_tools() |
Return names of all registered tools |
update_taint(risk) |
Update session taint risk monotonically (PDE engine only) |
Policy Format
Policies are JSON documents that map tool names to lists of rules. Each rule specifies whether to allow or deny a tool call and can include argument-level restrictions.
Full Format
{
"read_file": [
{
"priority": 1,
"effect": 0,
"conditions": {
"file_path": {
"type": "string",
"pattern": "^reports/.*\\.csv$"
}
},
"fallback": 0
}
],
"run_command": [
{
"priority": 1,
"effect": 1,
"conditions": {},
"fallback": 0
}
]
}
Shorthand Format (conditions only)
When you only need to restrict argument values, the shorthand skips priority, effect, and fallback (defaulting to allow, priority 1, raise on violation):
{
"read_file": {
"file_path": { "type": "string", "pattern": "^data/.*" }
}
}
Policy Rule Fields
| Field |
Type |
Description |
priority |
int |
Evaluation order — lower value runs first |
effect |
int |
0 = allow, 1 = deny |
conditions |
dict |
JSON Schema restrictions keyed by argument name |
fallback |
int |
0 = raise PolicyViolation, 1 = sys.exit(1), 2 = ask user |
Condition Schemas
Conditions follow JSON Schema syntax. Common patterns:
{ "type": "string", "pattern": "^/safe/path/.*" }
{ "type": "string", "enum": ["ls", "pwd", "cat"] }
{ "type": "integer", "minimum": 0, "maximum": 100 }
{ "type": "array", "items": { "type": "string" } }
Evaluation Logic
- Rules for a tool are evaluated in ascending
priority order.
- Allow rule (
effect=0): if all conditions pass → tool is allowed immediately.
- Deny rule (
effect=1): if all conditions match → tool is blocked using the configured fallback.
- If no rule matches → the tool is blocked by default.
- Tools not listed in the policy are blocked when a policy is loaded.
At equal priority, deny rules are evaluated before allow rules.
Missing arguments fail closed
A condition on an argument the call does not provide cannot be satisfied by omitting the argument:
- Allow rules: a condition naming an absent argument fails the rule, so the call falls through
to default-deny. An allow rule only vouches for calls that actually carry the arguments it
constrains.
- Deny rules: a condition on an absent argument matches vacuously, so the deny still applies.
This is controlled by PolicyEnforcer(strict_conditions=...), True by default. Setting it to
False restores the legacy behaviour of skipping conditions on absent arguments — only do this if
a policy deliberately means "constrain this argument if provided", and understand that a model
can then bypass the restriction by omitting the argument entirely.
Required arguments
Independently of conditions, required_args rejects calls whose named arguments are absent,
None