AI
Researchers develop targeted fixes for LLMs generating power-grid code, boosting accuracy by over 50%
A new benchmark and runtime workflow helps large language models overcome API knowledge gaps when writing simulation code for electrical grids.
Large language models show promise for converting high-level requests about electrical grids into executable simulation code, but deploying them on-premises reveals a persistent problem: models frequently fail at API boundaries, inventing functions that don't exist, applying parameters incorrectly, or misinterpreting data results.
A research team has tackled this challenge with PowerCodeBench, a diagnostic framework and runtime system that requires no model retraining. The work demonstrates substantial gains across open-weight LLMs and establishes a practical path for integrating AI-assisted code generation into utility operations.
The core problem#
When utilities and research labs deploy LLMs locally to generate power-system simulation code, first-pass failures cluster around application programming interfaces (APIs). The models produce hallucinated function calls, misuse library parameters, and struggle to parse returned data tables. This makes production deployment risky without heavy human review.
PowerCodeBench and diagnostic probes#
The researchers built a frozen 2,000-task benchmark suite for pandapower, a popular power-system simulation library. The system includes layered diagnostic probes—called L0 through L3—that test each model's understanding of the API at increasing depths. These probes:
- Generate per-model profiles showing exactly where knowledge breaks down
- Enable direct model-to-model comparison on API competence
- Inform decisions about documentation allocation and backend tuning
Runtime workflow boosts accuracy#
Rather than retraining, the approach uses a two-pronged runtime strategy: a query analyzer estimates what API evidence the model needs before generation begins, while execution feedback routes targeted repair when code fails. Tested on ten open-weight models (1.5B to 480B parameters) and four mid-tier APIs, this workflow lifted scalar-match accuracy by 32–56 percentage points over unassisted first-pass attempts—and this held true for every model of at least 7B parameters and every API tested. Even after three repair rounds, the gains persisted.
Real-world validation#
Among code that passed numerical checks under both workflows, engineering review confirmed that the requested analysis was correctly performed in 88% of full-workflow outputs, versus 66% under plain repair alone. Selective injection of API evidence recovered most of the gains from the full reference approach while using only 41% of the prompt tokens.

