AutoHarness: The AI That Learned to Write Its Own Rules
The Problem: LLMs Keep Breaking the Rules
In the recent Kaggle GameArena chess competition, an astonishing 78% of Gemini-2.5-Flash's losses came not from bad strategy, but from attempted illegal moves. A model that can write poetry, code, and pass bar exams repeatedly failed at basics like how a knight moves.
The core issue: LLMs learn statistical regularities ("knights *usually* move this way") rather than hard constraints ("knights *may only* move this way"). They lack a sense of inviolable boundaries in structured environments like board games.
Traditional fixes fall short:
- Fine-tuning is expensive, slow, risks catastrophic forgetting, and must be redone for every new game.
- Hand-written harnesses (verification code like
is_legal_move()) work but require dedicated engineering per game and are brittle to rule changes. - Code generation is framed as a search problem using Thompson sampling tree search: each node is a harness version, children are mutated variants, edge weights reflect test quality.
- The LLM serves as a smart mutation operator — receiving the code, failing test cases, and error messages, then producing targeted fixes rather than random changes.
- A Critic module categorizes failure cases (e.g., "3 failures from mishandling castling rules") to give the LLM structured feedback.
- Convergence takes an average of 14.5 iterations.
- 100% legal move rate across all 145 games once the harness converged.
- In 16 two-player games, Gemini-2.5-Flash + Harness achieved a 56.3% overall win rate against Gemini-2.5-Pro — a smaller model beating a larger one, compared to only 38.2% for the unassisted Pro.
- In 16 single-player games, Harness-as-Policy (generated by Gemini-2.5-Flash) scored 0.870 average reward, beating GPT-5.2-High (0.844), Gemini-2.5-Pro (0.707), and GPT-5.2 (0.635).
- Cost comparison: testing GPT-5.2 variants cost ~$640 in API fees; running Harness-as-Policy costs essentially nothing (pure Python execution).
- Each harness is environment-specific — a chess harness can't play Go.
- Harness-as-Policy underperforms in two-player adversarial games, where dynamic opponent modeling still favors LLM-in-the-loop modes.
- Fixed code doesn't learn: rule changes require regeneration.
- Constraint as liberation: well-designed boundaries let AI focus cognitive resources on what matters.
- Code as a universal interface: harnesses are portable, shareable, and composable across models.
- Small model + good tools > large model alone: future competition may hinge on tooling as much as scale.
DeepMind's insight: since LLMs are good at writing code, why not let them write their own harness?
What Is a Harness?
A harness is a control layer wrapped around the LLM, typically containing two functions:
1. propose_action(state) — proposes possible actions for the current game state.
2. is_legal_action(state, action) — checks whether a specific action is legal.
AutoHarness: AI Writing Its Own Constraints
The system gives the model a code template with empty functions, then iterates:
1. The model generates a first version of the harness code. 2. The code runs against the game environment and is tested. 3. Failures (illegal moves accepted, legal moves rejected) are fed back. 4. The model revises the code; repeat until 100% correct or max iterations reached.
Search and Refinement
Three Harness Modes
1. Harness-as-Action-Verifier (default): the LLM proposes a move; the harness rejects illegal ones and asks the model to retry. Preserves the model's strategic creativity. 2. Harness-as-Action-Filter: the harness enumerates *all* legal actions; the model picks from this pre-filtered list. Illegal moves become impossible, but the harness must exhaustively enumerate options. 3. Harness-as-Policy: the generated code contains the complete game strategy and runs without any LLM calls — near-zero cost, deterministic, but game-specific.
Results
Tested on 145 TextArena games (single- and two-player, excluding pure conversation games):
Why Does Constraint Improve Performance?
The answer is cognitive offloading: with rule-checking delegated to code, the LLM can devote its full capacity to strategy rather than juggling legality checks. Harness-as-Policy additionally benefits from specialization, determinism, iterative refinement baked into code, and zero latency.
Limitations
Implications
References
1. Lou, X., Lázaro-Gredilla, M., Dedieu, A., Wendelken, C., Lehrach, W., & Murphy, K. P. (2026). AutoHarness: improving LLM agents by automatically synthesizing a code harness. *arXiv preprint arXiv:2603.03329*. https://arxiv.org/abs/2603.03329 2. Guertler, T., et al. (2025). TextArena: A collection of text-based games for evaluating language models. https://github.com/PhilipGuertler/TextArena 3. Kaggle. (2025). GameArena Competition. https://www.kaggle.com/competitions/gamearena