Skip to content

Guardrails and Evaluation ​

Kompile exposes guardrails and evaluation at two layers, matching its two runtime surfaces:

  1. CLI & MCP Agent Harness (runs locally with zero server required) — Enforcer & Judge policies, Command Guardrails, the LLM Tool Gateway, agent evaluation suites (eval), the model performance harness (perf), and test milestones.
  2. Distributed Server (kompile-app) (runs on the admin console :8080) — RAG input/output content guardrails (kompile-guardrails) and dataset A/B experiments (kompile-evaluation).

Part 1: CLI & MCP Harness Guardrails & Evaluation ​

Harness Guardrail Layers ​

The coding-agent harness layers deterministic checks and LLM-backed oversight around tool execution:

LayerWhere it runsHow to inspect or configure
Deterministic Enforcer & HooksEvery tool call in kompile chat, kompile mcp-stdio, and kompile serve/judge, /policy-enforce, /hooks — see The Enforcer
Inline Compliance & Direction JudgeTool calls, turn completions, and subagent runs/judge, /judge-global, /direction — see The Judge
Command Guardrails (CommandGuardrail)Shell command regex rules (.kompile/config/command-guardrails.json, ~/.kompile/config/command-guardrails.json, or built-in defaults)/gateway status, /gateway rules
LLM Tool Gateway (CliToolGatewayInterceptor)Evaluates non-read-only tool calls (ALLOW / REWRITE / BLOCK) before execution across kompile chat, kompile mcp-stdio, and kompile serve/gateway (alias /guardrails), kompile configure gateway, kompile config tool-gateway
Periodic Transcript AuditsOut-of-band session review/policy-enforce — see Auditing & Provenance

Tool Gateway (CLI & MCP) ​

The Tool Gateway evaluates proposed tool calls against user-defined rules before execution and can ALLOW, REWRITE arguments, or BLOCK the call with corrective feedback.

  • Cheap, local read-only tools (read, grep, glob, list) always bypass LLM network evaluation so everyday search never stalls.
  • Disabled by default until enabled in ~/.kompile/config/tool-gateway-config.json (or feature-flags-config.json), adding zero overhead when off.
  • Rules live in ~/.kompile/config/tool-gateway-rules.json (shared with the server-side ToolGatewayService format).
bash
# Interactive setup wizard from the terminal
kompile configure gateway

# Inspect or update gateway settings
kompile config tool-gateway

Inside kompile chat:

text
/gateway status     # Show Tool Gateway state + active Command Guardrail source
/gateway rules      # List Tool Gateway rules and Command Guardrail patterns
/gateway setup      # Launch the interactive Tool Gateway wizard and hot-reload
/gateway reload     # Reload tool-gateway-config.json and rules without restarting
/guardrails         # Alias for /gateway

Configuration options: model source, fail-open behavior, dry-run mode, evaluation timeout, and per-rule conditions/actions.

Agent Evaluation Suites (eval) ​

The CLI evaluation harness runs structured YAML/JSON suites against coding agents, tracks pass/fail outcomes, optionally scores completions with a judge LLM, and stores historical runs for trend and side-by-side comparison.

It is exposed across all three harness surfaces:

  • CLI: kompile eval ...
  • Interactive chat: /eval ...
  • MCP tool (kompile mcp-stdio and kompile serve): eval (list_suites, list_runs, show_run, inspect_suite, create_suite, compare_runs, trend, delete_run)
bash
# Scaffold and validate a suite file
kompile eval create my-suite.yaml
kompile eval inspect my-suite.yaml

# Run an evaluation suite against an agent (optionally with judge scoring)
kompile eval run my-suite.yaml --agent claude-code --judge

# Inspect historical results and compare runs
kompile eval list
kompile eval report --suite "My Suite"
kompile eval show <run-id>
kompile eval compare <run-id-a> <run-id-b>
kompile eval delete <run-id>

Inside kompile chat:

text
/eval list                          # List discovered suite files
/eval report [suite-name]           # Show past evaluation runs
/eval show <run-id>                 # Inspect one stored run
/eval inspect <suite.yaml>          # Validate and summarize a suite file
/eval create <suite.yaml> [name]    # Scaffold a new suite file
/eval compare <run-a> <run-b>       # Compare two runs side by side
/eval trend <suite-name>            # Show pass-rate trend over time
/eval delete <run-id>               # Delete a stored run

Performance Harness (perf) ​

Track model and agent performance across task types, view leaderboards, and query recommendations. Exposed via:

  • CLI: kompile perf [report|recommend|config|reset]
  • Interactive chat: /perf [report [task]|recommend [task]|config|stats|reset --yes]
  • MCP tool: performance_harness (record, report, recommend, stats, config, reset)
bash
kompile perf report                    # View performance leaderboard
kompile perf recommend                 # Get model/agent recommendations
kompile perf config                    # View or update tracking settings
kompile perf reset                     # Clear collected records

Test Milestones ​

For day-to-day verification inside coding sessions, /test-milestones and the test_milestone MCP tool automatically capture test executions and record structured pass/fail verification milestones alongside your session transcript.


Part 2: Server-Side (kompile-app) RAG Guardrails & Experiments ​

When running the distributed server (kompile-app-main on :8080), Kompile adds RAG content guardrails (kompile-guardrails) and dataset experiments (kompile-evaluation) around retrieval and chat pipelines.

Input guardrails ​

GuardrailWhat it detects
Prompt injectionAttempts to override system instructions
JailbreakAttempts to bypass safety filters
PII detectionPersonal identifiable information in queries
ToxicityToxic or abusive language
TopicOff-topic queries
Business ruleViolations of custom business rules
Competitor mentionReferences to competitors
CopyrightCopyrighted content

Output guardrails ​

GuardrailWhat it detects
HallucinationResponses not supported by retrieved context
RelevancyResponses that don't address the query
FormatResponses that don't match expected format

Server guardrail configuration ​

Each server-side guardrail can be toggled individually on the admin console (:8080):

bash
# Via REST API
curl -X POST http://localhost:8080/api/guardrails/toggle \
  -H "Content-Type: application/json" \
  -d '{"guardrailType": "PROMPT_INJECTION", "enabled": true}'

# View guardrail status
curl http://localhost:8080/api/guardrails

You can also toggle them in the web UI (Settings > Guardrails) or via feature-flags-config.json.

Server-side experiments ​

Experiments group RAG evaluation datasets and runs for A/B testing on the admin console (:8080):

bash
# List experiments
curl http://localhost:8080/api/experiments

# Create an experiment
curl -X POST http://localhost:8080/api/experiments \
  -H "Content-Type: application/json" \
  -d '{"name": "Compare embedding models", "datasetId": "<id>"}'

Scheduled evaluation ​

Run evaluation suites on a schedule to detect regressions:

bash
kompile app schedule create --type=eval --cron="0 0 * * *" --suite=my-suite

When to use guardrails & evaluation ​

Guardrails add latency whenever an LLM or classifier evaluates a turn. Enable them selectively:

  • Coding-agent sessions: keep deterministic Enforcer rules on; add the Judge or Tool Gateway when you want policy enforcement or argument rewriting on shell/edit tools
  • External RAG users: prompt injection, jailbreak, PII
  • Regulated domains: business rules, copyright, competitor mention
  • Production RAG: hallucination, relevancy
  • Internal dev loops: keep heavy server-side content guardrails off unless testing them

Run evaluations when you:

  • Change prompts, agent instructions, or model failover ladders
  • Change the embedding model, chunking strategy, query transformation, or reranking settings
  • Add or remove data sources
  • Want to compare LLM providers or coding agents objectively
  • Why Kompile Is Opinionated — how the harness layers deterministic guards, judges, and audits
  • The Enforcer & The Judge — coding-agent policy rules and live compliance supervision
  • Information Retrieval — server-side guardrails wrap the retrieval pipeline; experiments measure its quality
  • Configuration — tool-gateway-config.json, tool-gateway-rules.json, command-guardrails.json, and feature-flags-config.json

Released under the Apache-2.0 License.