Software is the domain in which generative models meet the most useful kind of feedback.
A program can be run. Given a specification and a few unit tests, a machine can say in milliseconds whether a candidate passes, with no human in the loop and at a cost that is tiny next to the cost of producing the candidate. That is why code is where sampling many candidates and checking them (the companion book), reinforcement learning against a programmatic verifier, and multi-step agents that read error messages have all been pushed furthest.
The signal is also weaker than it looks. A test suite is a finite sample of the behaviours that matter. A program that passes it may be right, or wrong only on inputs the suite never tries, or wrong in a way the suite cannot express at all (it is slow, it leaks memory, it executes input as code). Every method in this article turns on one question: how much does “all tests pass” tell us about “this program is correct”, and how does that change what we should do with many samples, many retries and a learning signal that is the pass/fail bit?
We work on three connected problems. Generating code from a specification, where quality is measured by the probability that a sample is correct and reported as pass@k. Verifying and repairing, where a loop samples candidates, runs tests, and feeds failures back, under a budget of attempts and money. Learning from test feedback, where the pass/fail bit is a reward. For each we derive what can be said exactly, and then test it on synthetic tasks where the truth is known.
Three limits, stated early. First, the “language model” in every experiment is a deterministic stand-in: a categorical distribution over a fixed pool of candidate programs for each task. The programs are real Python source, executed by a real sandboxed runner, and the tests are real. Only the choice of program is simulated. What carries over to real models is the statistics of sampling, verification, cost and learning against a verifier. The absolute numbers do not carry over. Second, the tasks are small synthetic functions on lists of integers generated in code; no third-party code or benchmark is used, so nothing here says how any real system performs on real repositories. Third, this article is educational and is not professional advice. A runner that executes generated code is a security-sensitive component, and the sandbox in the companion book example is not a security boundary. the companion book example lists what a software-security reviewer must check before any of these ideas touch a real pipeline.
the companion book follows the eight-part template of the vertical chapters. Sections 7.1 and 7.2 state the problem and formalize it. Sections 7.3 and 7.4 implement the runner and the synthetic world. Sections 7.5 to 7.8 are the method and derivation (Theorems 7.1 to 7.5). the companion book example is the worked example, a repair agent end to end, with Proposition 7.7. Sections 7.10 and 7.11 extend it to learning (Theorem 7.6) and retrieval, the companion book example is the evaluation, Sections 7.13 and 7.14 are the failure modes and the reviewer’s checklist, and the exercises close the companion book.
Continue with the book
Explore the full treatment, worked examples, and exercises in Applied AI for Generation and Control.
Companion article for Applied AI for Generation and Control, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
