Viverra: Text-to-Code with Guarantees

Haoze Wu, Rocky Klopfenstein, Keith Farkas, Nina Narodytska

TL;DR

Large Language Models write code fast, but reviewing that code to make sure it doesn't harbor subtle, catastrophic bugs can take just as long as writing it from scratch. Enter VIVERRA, a system that doesn't just generate C code from plain English—it simultaneously generates and mathematically verifies "facts" about what that code actually does, embedding them as plain-English comments. By trading absolute mathematical perfection for fast, bounded guarantees, VIVERRA helps exhausted developers audit AI-generated code faster and more accurately.

What Problem Does This Paper Address?

Here is the dirty secret of AI coding assistants: they shift the bottleneck from writing code to reading and auditing it. Because LLMs offer zero guarantees of correctness, a human still has to stare at the generated logic to make sure it actually matches their intent.

Historically, we have two ways to check code, sitting at opposite extremes:

  1. Testing: Easy and practical, but running a few test inputs only proves the code worked on those specific inputs. Bugs still hide in the dark corners.
  2. Full Formal Verification: Using mathematical proof assistants (like Lean or Rocq) to prove code is 100% bug-free across all possible realities. It’s ironclad, but notoriously difficult and time-consuming—even with AI help—and usually requires specialized programming languages.

The authors ask: Is there a practical middle ground for standard languages like C? Can we automatically hand developers mathematically verified clues about how AI-generated code behaves, without requiring a PhD in formal methods or hours of compute time?

Methods

VIVERRA bridges this gap by combining an LLM (GPT-5.1) with off-the-shelf bounded model checkers (CBMC and ESBMC)—automated tools that exhaustively check every possible execution path of a program, provided you cap how many times loops are allowed to spin (say, $k=5$ iterations).

Figure 1: Overview of VIVERRA.

The pipeline relies on two clever compromises:

  • Partial Co-Specification (New): Instead of asking the human to write formal specs, VIVERRA takes a natural-language prompt and asks the LLM to generate both a verification-friendly C program (e.g., avoiding recursion) and a checklist of safety/correctness properties, which it embeds into the code as assert() statements.
  • Bound Reduction & Best-Effort Compositional Verification (New): Because standard model checkers choke if a loop can run past the unwind limit $k$, VIVERRA prompts the LLM to shrink compile-time loop constants in a copy of the code so loops run at most $k$ times. It then traverses the program's call graph (using standard parsing tools like libclang) to verify assertions in order. If an assertion can't be proven standalone, VIVERRA tries compositional verification: it promotes earlier assertions into assumptions (assume()) to see if the current assertion holds conditionally, tracking the exact chain of dependencies.

Finally, any unverified or falsified assertions are thrown out. Surviving assertions are translated back into plain English comments—tagged with their loop bound k and any conditions—and pasted into the original C code for the developer to read.

Datasets

VIVERRA uses no training datasets (it relies on zero/few-shot prompting via API). For evaluation, the authors introduce 17 diverse Text-to-C-Code tasks. Unlike canonical, bite-sized benchmarks like HumanEval or MBPP, these represent more complex, multi-function C programs—ranging from implementing the Simplex algorithm and Gaussian elimination to Sudoku solvers, Connect4, and log timestamp filters. They also created a 10-question code-comprehension survey for a human study on Amazon Mechanical Turk.

Key Insights and Ideas

  • Imperfect verification is still super useful: You don't need a complete proof of an entire program to help a developer. Knowing for a mathematical fact that "for up to 5 loop iterations, this array is sorted in non-decreasing order" narrows down what a human needs to manually check.
  • Co-generation avoids the specification bottleneck: Nobody likes writing formal specifications. Having the LLM draft candidate assert() statements from the same prompt it used to write the code gives the model checker targets for free—and the model checker keeps the LLM honest by discarding anything it can't prove.
  • Verification overhead pays off in human comprehension: Even when reading verified //FACT comments slowed readers down slightly on a tricky question, their comprehension accuracy skyrocketed—proving the annotations surface non-obvious program behaviors.

Key Results

Across the 17 benchmarks (with loop bound $k=5$ and a 60-second timeout per assertion), VIVERRA generated an average of 30.2 assertions per program, successfully verifying 27.9 unconditionally and 0.3 conditionally, leaving only ~1.3 unverified on average.

Table 1: Verification results per benchmark. LLM (s) is total wall-clock time for all LLM calls (synthesis, annotation, bound reduction, mapping, translation); Verify (s) is total verification time.
  • Speed: LLM synthesis/processing took an average of 162.8s per benchmark, while verification took 316.4s (ranging from 2.4s on shift_letter to 2,077.6s on sudoku, where global grid-uniqueness properties taxed the solvers).
  • Human Study (400+ task completions): Crowdworkers with IT backgrounds answered multiple-choice comprehension questions about the generated C code. Participants given VIVERRA's //FACT-annotated code achieved higher accuracy on 8 out of 10 questions (for instance, jumping from 40% to 100% on a connected-components ordering question) and answered faster overall (and faster on 6 of 10 benchmarks among correct respondents) compared to reading unannotated code.

Limitations and Future Work

  • The Bound-Reduction Catch: VIVERRA proves facts on the bound-reduced program ($P^+_k$), not the full-scale program ($P_0$) handed to the user. If shrinking loop constants hides a bug that only triggers on iteration 6, VIVERRA won't catch it.
  • False Sense of Security: Partial guarantees might trick complacent developers into thinking the whole program is bug-free. Better UI design is needed to communicate the exact scope of these guarantees.
  • Verifier Bottlenecks: Bounded model checkers struggle with global relational properties (like sorting density in knapsack) and sometimes over-approximate math operators, causing spurious failures (14/23 assertions failed in base_addition despite valid C logic).
  • Future Directions: Parallelizing assertion checks to slash verification time, expanding to languages like Python or Rust, handling complex heap/quantified properties, and running larger comprehension studies with professional software engineers.

Summary updated

Abstract

A fundamental limitation of Text-to-Code is that no guarantee can be obtained about the correctness of the generated code. Therefore, to ensure its correctness, the generated code still has to be reviewed, tested, and maintained by developers. However, parsing through LLM-generated code can be tedious and time-consuming, potentially negating the productivity gains promised by AI-coding tools. To address this challenge, we present Viverra, a system that automatically produces *formally verified annotations* alongside generated code to aid user's understanding of the generated program. Given a natural-language task description, Viverra prompts an LLM to synthesize a C program together with candidate assertions expressing safety and correctness properties. It then verifies those assertions in a compositional and best-effort manner via a portfolio of bounded model checkers. Evaluation on 17 diverse programming tasks suggests that Viverra can efficiently generate code with verified assertions, and that these assertions improve users' performance on code-comprehension tasks in a user study with more than 400 task completions.
BibTeX
@inproceedings{wu2026viverra,
  author = {Haoze Wu and Rocky Klopfenstein and Keith Farkas and Nina Narodytska},
  title = {{Viverra: Text-to-Code with Guarantees}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=35jwwbZdxS},
}
Figure