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 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.
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.
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.
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.
- 01
Complex functions
Deep nesting and long branching chains, reported as
loki/shape-anomaly. - 02
Swallowed errors
Catch blocks that hide a failure or report success after one.
- 03
Weakened tests
Assertions removed, or tests marked skip so they stop failing.
- 04
Duplicated functions
A second copy of logic that already exists in the file.
- 05
Shell writes
Files written through shell redirects that bypass the edit hooks.
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
| Rank and model | Erosion | Verbosity | Cost per checkpoint | Strict solve rate |
|---|---|---|---|---|
| 5 + Loki GPT 6.1 SOL (Medium) with Loki | 0.091 | 0.109 | $0.44 | 12.24% |
| 1 GPT 5.6 SOL (XHigh) | 0.658 | 0.376 | $3.84 | 14.29% |
| 2 GPT 6 Astra (XHigh) | 0.559 | 0.158 | $3.87 | 16.33% |
| 3 Opus 5.5 (Medium) | 0.700 | 0.347 | $0.99 | 14.29% |
| 4 GPT 6 Astra (Medium) | 0.701 | 0.229 | $1.33 | 14.80% |
| 5 GPT 6.1 SOL (Medium) | 0.704 | 0.218 | $0.91 | 14.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
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-guardrailsloki init --dir .