# Sieve-df: a Rust fuzzer for LLM structured-output engines (llguidance, outlines)

> Source: <https://github.com/Flotrpy/sieve-df>
> Published: 2026-12-05 18:11:18+00:00

**Key takeaway:** sieve-df drives llguidance and outlines-core as linked Rust crates and XGrammar through a JSON-lines subprocess bridge, using only an ungated tokenizer.json to find mask contradictions, dead ends and cross-engine disagreements, then shrinks each to a minimal schema plus token path.

At every decoding step sieve-df checks whether an engine's token mask allows exactly the
right tokens for a JSON Schema. It needs **no model weights**: it loads an ungated
`tokenizer.json` (for example a Qwen tokenizer from Hugging Face) and does random token walks
over the mask, weighted toward boundary tokens such as `":`, `"},{"` and leading-space tokens.

| Engine | How it is driven | 
|---|---|
| [llguidance](https://github.com/guidance-ai/llguidance) | Rust crate, linked directly | 
| [outlines-core](https://github.com/dottxt-ai/outlines-core) | Rust crate, linked directly | 
| [XGrammar](https://github.com/mlc-ai/xgrammar) | Python, through a JSON-lines subprocess bridge | 
| [llama.cpp](https://github.com/ggml-org/llama.cpp) grammar sampler (optional) | via llama-cpp-python and a vocab-only GGUF generated from `tokenizer.json` ;`scripts/setup_llamacpp.sh` ; needs a real tokenizer | 

Everything is free and open source; nothing needs an account, API key or card.

1. **Contradictions** – the mask allows a token, but the engine rejects it when it is fed.
2. **Dead ends** – an allowed token leads to a state with an empty mask that cannot finish.
3. **Disagreements** – two engines differ on one token. To decide who is right sieve-df tries to
finish the output and validates it with[jsonschema-rs](https://github.com/Stranger6667/jsonschema) :
a valid finish means the*blocking* engine is too strict; if none can be produced, the*allowing* engine is too loose.
4. **Invalid outputs** (EOS allowed for a document that violates the schema),**crashes** (engine
panics, isolated) and**hangs** (compile blow-ups).

Each bug is shrunk to a minimal schema plus token path, written as a markdown issue draft, and counted in an engine x JSON Schema feature x tokenizer table.

```
cargo build --release
examples/quickstart.sh            # built-in vocabulary, bundled schemas, no downloads
```

With a real tokenizer and the other engines:

``` php
scripts/fetch_tokenizer.sh        # Qwen2.5 tokenizer.json -> data/tokenizers/qwen2.5.json
scripts/setup_xgrammar.sh         # optional: .venv with XGrammar (no torch needed)
scripts/fetch_corpora.sh          # optional: JSON Schema Test Suite + JSONSchemaBench

target/release/sieve-df run \
  --tokenizer data/tokenizers/qwen2.5.json \
  --engines llguidance,outlines-core,xgrammar \
  --builtin --mcp examples/mcp \
  --suite data/corpora/json-schema-test-suite \
  --bench data/corpora/jsonschemabench --bench-subsets Handwritten,Kubernetes \
  --mutants 3 --walks 20 --out out/run
```

| Command | Purpose | 
|---|---|
| `sieve-df run` | fuzz: random walks ( `--mode single\|differential\|both` ) over the selected schemas; writes`findings.jsonl` ,`findings/*.json` ,`stats.json` | 
| `sieve-df replay <findings>` | re-run saved findings and report whether they still reproduce | 
| `sieve-df shrink <findings>` | reduce findings to a minimal schema + token path, deduplicated into unique bugs ( `minimized.jsonl` ) | 
| `sieve-df report --minimized …` | write one markdown issue draft per bug, `results.md/csv` and`index.md` | 
| `sieve-df bench` | compile and mask-computation latency per engine | 

Schema sources for `run` and `bench`: `--schemas` (files/dirs), `--mcp` (MCP tool definitions),
`--suite` (JSON Schema Test Suite), `--bench` (JSONSchemaBench), `--builtin`, plus `--mutants N`
to add mutated variants (nested `anyOf`, `$ref` recursion, `pattern`, unicode enums, escaped
keys, bounds), `--filter`, `--limit`, `--shuffle`.

`fuzz/` holds cargo-fuzz targets that feed mutated schemas and walks to the linked engines
with libFuzzer's coverage feedback; see [fuzz/README.md](https://github.com/Flotrpy/sieve-df/blob/main/fuzz/README.md).

- [docs/findings.md](https://github.com/Flotrpy/sieve-df/blob/main/docs/findings.md) – bugs found so far, each pinned by a test
- [docs/architecture.md](https://github.com/Flotrpy/sieve-df/blob/main/docs/architecture.md) – design, oracles, bridge protocol
- [CONTRIBUTING.md](https://github.com/Flotrpy/sieve-df/blob/main/CONTRIBUTING.md) – setup, rules, adding engines and mutations

MIT
