Compiled AI: Deterministic Code Generation for LLM-Based Workflow Automation
Organizations: XY.AI Labs, Palo Alto, CA · Stanford University School of Medicine, Stanford, CA · Cornell University, Ithaca, NY · Cornell University, Department of Computer Science, Ithaca, NY ·
Abstract
We study compiled AI, a paradigm in which large language models generate executable code artifacts during a compilation phase, after which workflows execute deterministically without further model invocation. This paradigm has antecedents in prior work on declarative pipeline optimization (DSPy) and hybrid neural-symbolic planning (LLM+P); our contribution is a systems-oriented study of its application to high-stakes enterprise workflows, with particular emphasis on healthcare settings where reliability and auditability are critical. By constraining generation to narrow business-logic functions embedded in validated templates, compiled AI trades runtime flexibility for predictability, auditability, cost efficiency, and reduced security exposure. We introduce (i) a system architecture for constrained LLM-based code generation, (ii) a four-stage generation-and-validation pipeline that converts probabilistic model output into production-ready code artifacts, and (iii) an evaluation framework measuring operational metrics including token amortization, determinism, reliability, security, and cost. We evaluate on two task types: function-calling (BFCL, n=400) and document intelligence (DocILE, n=5,680 invoices). On function-calling, compiled AI achieves 96% task completion with zero execution tokens, breaking even with runtime inference at approximately 17 transactions and reducing token consumption by 57x at 1,000 transactions. On document intelligence, our Code Factory variant matches Direct LLM on key field extraction (KILE: 80.0%) while achieving the highest line item recognition accuracy (LIR: 80.4%). Security evaluation across 135 test cases demonstrates 96.7% accuracy on prompt injection detection and 87.5% on static code safety analysis with zero false positives.
Figures & tables
| Method | GenTokens | Runtime/tx | Total@1K | BreakEven | CompRatio |
|---|---|---|---|---|---|
| Direct LLM | 0 | 552 | 552,000 | n/a | n/a |
| LangChain | 0 | 740 | 740,000 | n/a | 0.75 |
| AutoGen | 0 | 805 | 805,000 | n/a | 0.69 |
| Compiled AI | 9,600 | 0 | 9,600 | 17 tx | 57 |
| Method | Inference | Infra | Total TCO | CostRatio |
|---|---|---|---|---|
| Direct LLM | $21,500 | $500 | $22,000 | 40 |
| LangChain | $28,900 | $500 | $29,400 | 53 |
| AutoGen | $31,400 | $500 | $31,900 | 57 |
| Compiled AI | $55 | $500 | $555 | 1 |
| Paradigm | Approach | KILE | LIR | Latency | LLM Calls |
|---|---|---|---|---|---|
| Compiled AI | Deterministic (Regex) | 20.3% | 59.7% | 0.6 ms | None |
| Code Factory | 80.0% | 80.4% | 2,695 ms † | Compiled | |
| Runtime AI | Direct LLM | 80.0% | 74.5% | 6,339 ms | Per-request |
| LangChain | 80.0% | 75.6% | 6,207 ms | Per-request | |
| AutoGen | 77.8% | 78.9% | 13,742 ms | Per-request | |
| † Median latency; mean 10,263 ms due to 10% retry outliers (max 183s). First compile: 57s. | |||||
Code Generation
Code generation studies methods for turning natural-language, visual, or formal specifications into executable programs and code edits.
See all 313 papers