Synthetic Programming Elicitation for Text-to-Code in Very Low-Resource Programming and Formal Languages

Federico Mora, Justin Wong, Haley Lepe, Sahil Bhatia, Karim Elmaaroufi, George Varghese, Joseph E. Gonzalez, Elizabeth Polgreen, Sanjit Seshia

Large Language Models (LLMs) are like polyglots who have read the entire internet. They are incredibly fluent in "world languages" like Python and Java, but they stumble blindly when asked to speak "regional dialects"—niche, domain-specific, or formal verification languages that have very little representation in their training data.

In their NeurIPS 2024 paper, researchers from UC Berkeley and several other institutions introduce SPEAC (Synthetic Programming Elicitation and Compilation), a framework designed to help LLMs write code for these "Very Low-Resource Programming Languages" (VLPLs) by meeting the models where they are already comfortable.

TL;DR

SPEAC enables LLMs to generate syntactically correct code for niche languages (like UCLID5) by using a "natural" intermediate language—such as a specific subset of Python—and then using formal compiler techniques to automatically repair and translate that code into the target language. It boosts the success rate of generating parsable code from roughly 10% to over 80%.

What Problem Does This Paper Address?

Most code-generation benchmarks focus on popular languages. However, in high-stakes engineering, we often use Very Low-Resource Programming Languages (VLPLs). These include internal domain-specific languages (DSLs) used at large tech companies or formal verification languages like UCLID5, used to prove that hardware or software is bug-free.

An example of a natural language prompt and the corresponding target UCLID5 code, illustrating the conceptual and syntactic gap LLMs face.

LLMs fail at VLPLs for two reasons:

  1. Data Scarcity: There aren't enough examples online for the model to learn the syntax.
  2. Conceptual Mismatch: VLPLs often use specialized concepts (like "transition systems") that don't map cleanly to the standard procedural or object-oriented patterns LLMs "prefer."

Standard fixes like fine-tuning or few-shot prompting often produce code that looks right at a glance but is riddled with syntax errors that prevent it from even compiling.

Methods

The authors propose a three-part workflow called SPEAC:

The SPEAC workflow, showing how an LLM generates intermediate code which is then repaired and iteratively refined if holes are present.
  1. Synthetic Programming Elicitation: Instead of forcing the LLM to learn the niche language, the researchers studied what the LLM naturally does when asked to solve a problem using a hypothetical Python API. They found that LLMs tend to use specific object-oriented patterns. They used these insights to design an intermediate language ($C$) that feels "natural" to the LLM but is mathematically easy to map to the target language ($T$).
  2. Automated Repair (The "A" in SPEAC): When an LLM generates code in the intermediate language, it might still make mistakes (like type mismatches). SPEAC uses MAX-SMT solvers to find the "Largest Consistent Subtree"—essentially identifying the biggest part of the code that is valid and turning the broken parts into "holes" (marked as ??).
  3. Iterative Refinement & Compilation: The system can either use the SMT solver to fill those holes automatically or ask the LLM to try again just for those specific snippets. Once the intermediate code is perfect, it is compiled into the target VLPL.

Datasets

The researchers evaluated SPEAC using UCLID5 as the target VLPL:

  • Elicitation Set: 33 regression tests with handwritten natural language descriptions used to study LLM tendencies.
  • Fine-tuning Set: 317 regression tests from the UCLID5 GitHub repository.
  • Evaluation Set: 33 complex exercises and examples pulled from three major formal methods textbooks (e.g., Principles of Model Checking). These represent "unseen" challenges that require actual reasoning, not just pattern matching.

Key Insights and Ideas

  • Embrace the Hallucination: Instead of fighting the LLM's tendency to use Python-like syntax, SPEAC leans into it. By providing a Python-based "wrapper" for the niche language, the model can focus on the logic while the compiler handles the esoteric syntax.
  • Aggressive Repair is Good for Models: While a human programmer might find it annoying if a compiler "silently fixed" their code, LLMs benefit from this. The MAX-SMT approach acts as a "syntactic guardrail" that forces the model's output into a valid state.
  • Syntax vs. Semantics: The study found that LLMs often get the logic of a formal model right but fail on the syntax. By solving the syntax problem through compilation, the underlying "intelligence" of the LLM for problem-solving is finally unlocked for niche languages.

Key Results

The results were dramatic when comparing SPEAC to standard prompting (In-Context Learning) and fine-tuning:

Method Parse Rate (Syntactic Correctness)
GPT-4t (Standard Prompting) 12.1%
GPT-3.5t (Fine-tuned) 6.1%
SPEAC (with GPT-4t) 72.7%
SPEAC (with GPT-3.5t) 84.8%

Beyond just parsing, the semantic correctness (whether the code actually does what it's supposed to) was also high. For the 28 programs SPEAC generated that passed the compiler, nearly 40% were rated as "fully correct," and many others had only minor, easily fixable errors.

Limitations and Future Work

  • Human in the Loop: Designing the intermediate language and the compiler currently requires a human expert who understands both the LLM's tendencies and the target VLPL.
  • Single Case Study: While the results for UCLID5 are impressive, the authors acknowledge that SPEAC needs to be tested on other VLPLs (like CUDA or legacy industrial languages) to prove its generality.
  • Evaluation Bias: Semantic correctness was manually assessed by a single author; future work could involve more diverse expert reviews or automated property checking.

Ultimately, SPEAC suggests that the best way to use LLMs for specialized tasks isn't to teach the model a new language, but to build a better "translator" that speaks the model's native tongue.

Summary updated

BibTeX
@inproceedings{mora2024synthetic,
  author = {Federico Mora and Justin Wong and Haley Lepe and Sahil Bhatia and Karim Elmaaroufi and George Varghese and Joseph E. Gonzalez and Elizabeth Polgreen and Sanjit Seshia},
  title = {{Synthetic Programming Elicitation for Text-to-Code in Very Low-Resource Programming and Formal Languages}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=kQPzFiwVIu},
}
Figure