Loki

Loki Guardrails 0.4.6, MIT license, one Rust binary

Make your agent write code people can read.

Loki checks each edit your coding agent proposes. An edit that fails is never written, and the agent is told what to fix.

cargo install loki-guardrails
Watch the 80-second film
Proposed by the agentRefused
 1def watch(cfg, store, workers, timeout, strict, retry): 2for w in workers: 3if w.active: 4if cfg.mode == "live": 5for item in w.queue: 6if item.valid: 7if strict and item.kind != "noop": 8if store.has(item.id): 9if timeout > 0:10store.put(item.id, item.data)

cfgpipe.py:1 loki/shape-anomaly
Nesting depth 9. Split it into helpers.

Rewritten by the agentAllowed
 1def watch(cfg, store, workers): 2if cfg.mode != "live": 3return 4for worker in active_workers(workers): 5flush_worker(worker, store, cfg) 6 7def flush_worker(worker, store, cfg): 8for item in valid_items(worker.queue, cfg.strict): 9if store.has(item.id) and cfg.timeout > 0:10store.put(item.id, item.data)

cfgpipe.py: 0 findings
Nesting depth 2.

The same function, before and after Loki refused the first edit. The vertical lines mark each level of nesting.
Works with
Claude Code, Codex, Antigravity, Factory, Pi and OMP
Checks
Python, TypeScript, JavaScript, Go, Rust and Elixir
01Film, 80 seconds, with sound

What does Loki do to an edit?

Four edits go through Loki: a deeply nested function, a swallowed error, a skipped test and a duplicated calculation. Each is refused, then rewritten.

02Checks

What does Loki check for?

Loki runs locally as one Rust binary and makes no LLM call. It reports only what the edit changed, so existing problems do not block new work.

  1. 01

    Complex functions

    Deep nesting and long branching chains, reported as loki/shape-anomaly.

  2. 02

    Swallowed errors

    Catch blocks that hide a failure or report success after one.

  3. 03

    Weakened tests

    Assertions removed, or tests marked skip so they stop failing.

  4. 04

    Duplicated functions

    A second copy of logic that already exists in the file.

  5. 05

    Shell writes

    Files written through shell redirects that bypass the edit hooks.

03Evidence, SlopCodeBench

How does Loki compare with the SlopCodeBench top five?

With Loki, the fifth-ranked model wrote code with about one sixth of the erosion of the best top-five entry. It cost less than half as much per checkpoint as the cheapest.

  • Erosion0.091Best of the top five: 0.559
  • Verbosity0.109Best of the top five: 0.158
  • Cost per checkpoint$0.44Cheapest of the top five: $0.91
  1. GPT 6.1 SOL (Medium) with Loki0.091
  2. GPT 5.6 SOL (XHigh)0.658
  3. GPT 6 Astra (XHigh)0.559
  4. Opus 5.5 (Medium)0.700
  5. GPT 6 Astra (Medium)0.701
  6. GPT 6.1 SOL (Medium)0.704
Erosion, from 0 to 1. Lower is better. The top five are ranked by isolated solve rate on the SlopCodeBench leaderboard.
36 Python problems, 196 checkpoints, same prompt
Rank and modelErosionVerbosityCost per checkpointStrict solve rate
5 + Loki GPT 6.1 SOL (Medium) with Loki0.0910.109$0.4412.24%
1 GPT 5.6 SOL (XHigh)0.6580.376$3.8414.29%
2 GPT 6 Astra (XHigh)0.5590.158$3.8716.33%
3 Opus 5.5 (Medium)0.7000.347$0.9914.29%
4 GPT 6 Astra (Medium)0.7010.229$1.3314.80%
5 GPT 6.1 SOL (Medium)0.7040.218$0.9114.80%

Loki had the lowest erosion, verbosity and cost in this table. It also had the lowest strict solve rate: 12.24%, against 14.29% to 16.33% for the top five. The Loki project does not report an isolated solve rate for this run, so the run has no rank of its own.

Erosion
The share of complexity that sits in functions with cyclomatic complexity above 10.
Verbosity
The fraction of code lines flagged as wasteful or duplicated. It runs from 0 to 1, and lower is better.
Checkpoint
One stage of a problem, with its own requirements and tests. Cost is the model API cost for one stage.
Solve rates
Isolated: the checkpoint passes its own tests. Strict: it also passes the tests of every earlier checkpoint.

SlopCodeBench leaderboard and definitions · Loki run and method

04Install

How do I install Loki?

Install the binary with Cargo. Then run the second command in the repository where your agent works to set up its hooks.

cargo install loki-guardrails
loki init --dir .