Feed 0% source
Engineering AI-generated

Knowledge Boundary Probing and Demand-Guided Intervention for LLM-Based Power System Code Generation

Generated by a local model (nvidia/Gemma-4-26B-A4B-NVFP4) from a scientific paper, claim-checked against the full text. Provenance is open by design.

Small AI models often fail at power grid tasks not because they can't think, but because they forget specific technical commands. This research identifies that the primary bottleneck in power-system code generation is not a lack of reasoning. Instead, it is "API-knowledge boundaries"—errors like hallucinated function names, misused parameters, or mishandled result tables in specialized simulation libraries. By identifying exactly what a model doesn't know and injecting the correct documentation at the right time, the authors show we can allow smaller, private, on-premise models to perform as accurately as expensive, cloud-based APIs.

The Problem

In the energy sector, utilities and research labs rarely use hosted, closed-source APIs. They require on-premise serving for data confidentiality, regulatory compliance, and reproducibility. The standard fallback is deploying open-weight LLMs (models whose weights are publicly available) on-premise. However, the industry consensus has been that small-to-mid-size models are too unreliable for complex power-system analysis.

The authors argue this view misses the actual failure mode. As shown in, the problem isn't necessarily a lack of logical capacity.

Figure 1
Figure 1. Reliability workflow for LLM-based power-system code generation. Data flow per item: natural-language grid-analysis request →LLM-generated program →execution on the target grid case →scalar engineering output.

Rather, the model hits a "knowledge boundary" where it fails to correctly invoke the domain-specific library (pandapower). These first-pass failures are dominated by API-driven non-execution. This means the model hallucinates a function name or misconfigures a parameter. Simply scaling up the model size is an inefficient way to solve a problem that is essentially a documentation retrieval and precision issue.

How It Works

The proposed solution is a deployment-time reliability workflow. It requires no fine-tuning or modification of model weights. It consists of three interconnected components :

  1. L0–L3 Probing: Before deployment, the system runs a hierarchical probing procedure. It tests the model across four layers of competence: Recognition (L0), Recall (L1), Comprehension (L2), and Application (L3). This process converts the API specification into a per-model "risk profile" $\rho_M(f)$. This profile quantifies exactly where a model's knowledge breaks down for any given function $f$ .
Figure 3
Figure 3. The L0–L3 probe generator and profile output. Structured API documentation is transformed into recognition, recall, comprehension, and application probes, then aggregated into a model-specific knowledge-risk profile ρM(f) over the API corpus.
  1. Demand-Guided Probing: At inference time (the stage where the model generates a response), a query-side demand estimator predicts which API functions a natural-language query is likely to require. This ensures the system targets the specific tools needed for the task.
  2. Boundary-Aware Intervention: This is a two-phase loop. In the Proactive Phase, the system intercepts the prompt. It injects only the specific documentation layers that the model's risk profile suggests it lacks. In the Reactive Phase, if the code fails during execution, a router analyzes the error. It distinguishes between code-syntax errors and value-mismatch errors (where the code runs but the result is numerically incorrect). It then injects targeted "boundary cards" or API contracts to guide a repair attempt .
Figure 5
Figure 5. Boundary-aware intervention: two-phase pipeline. Phase 1 (Proactive) injects layer-specific API documentation before generation, guided by task demand ˆd(f, q) and model-specific knowledge deficits over L0–L3.

Numbers

The results are significant enough to change the math for on-premise deployment. The authors report that the intervention lifts the accuracy of every evaluated open-weight model ($\ge$7B parameters) and every commercial API by 32 to 56 percentage points.

Crucially for engineers managing hardware budgets, the method enables a "workload-aware" deployment strategy. The paper finds that mid-size open-weight models in the 70B–120B range match the accuracy of the four tested mid-tier commercial APIs .

Figure 6
Figure 6. Cross-vendor results for the 9-model panel of Table 3 (5 strongest open-weight + 4 mid-tier APIs). (a) Accuracy trajectory across the architecture-level progression A →C →C+FDRS. Open-weight models use solid lines with circular markers; APIs use dashed lines with square markers.

For example, Llama-3.1-70B and GPT-OSS-120B fall inside the mid-tier API accuracy range. Furthermore, the proactive injection is highly efficient regarding context window management (the amount of text a model can process at once). The authors demonstrate that this method reaches the accuracy ceiling of a "full-context" dump while using only 41% of the prompt-token cost . This saves over 2,000 tokens per item. This represents a massive saving in both latency and compute overhead per successful generation.

What's Missing

While the results are compelling, there are several gaps. First, the benchmark is currently limited to the pandapower library. Moving to other backends like MATPOWER or OpenDSS would require regenerating the entire API contract and probe suite.

Second, the paper focuses almost exclusively on accuracy-side improvements. It does not report on hardware-dependent metrics such as tail latency (the delay experienced by the slowest requests) or total energy consumption. For a utility, knowing the accuracy is vital. However, knowing the impact on the inference server's P99 latency is equally critical. Finally, the effectiveness of the demand predictor relies on a "transductive adaptation" assumption. This assumes you have access to an unlabeled corpus of target-domain queries to refine the ranker before deployment.

Should You Prototype This

Yes, if you are tasked with deploying LLMs in a privacy-constrained environment. The core insight is that API hallucinations are a solvable deployment-time problem. You don't need to spend weeks fine-tuning a 405B model. You can potentially get "API-grade" performance out of a 70B model on your own hardware.

The code for the PowerCodeBench benchmark is reportedly available at https://github.com/huiwxing/PowerCodeBench. If your workflow involves heavy use of versioned scientific libraries, this is a more efficient path to reliability than brute-force scaling.

Figures from the paper

Figure 2
Figure 2. Frozen-release composition statistics. (a) Item count per difficulty level (D1–D4). (b) Task-family frequency distribution across the 15 families sampled in this release. (c) Grid network size distribution across the 39 test cases used (bus count).
Figure 4
Figure 4. Table 2: Mean L0–L3 knowledge probe scores across all 275 pandapower API entries, for every open-weight model in the evaluation panel and the four closed-source API models from Section 7.2.
Novelty
0.0/10
Overall
0.0/10
#Large Language Models#Power Systems#Code Generation#API Knowledge#On-premise AI
How this was made
Generation

Model: nvidia/Gemma-4-26B-A4B-NVFP4
Persona: habr_engineer
Refinement: 0
Pipeline: forge-1.0

Verification

Evaluator: nvidia/Gemma-4-26B-A4B-NVFP4
Score: 96% (passed)
Claims verified: 13 / 13

Translation

Model: nvidia/Gemma-4-26B-A4B-NVFP4

Hardware & cost

NVIDIA GB10 · 128 GB unified · NVFP4 · 100% local · $0 cloud
Tokens: 159,619
Wall-time: 446.8s
Tokens/s: 357.2