Skip to content
Preprint

BeSpec: Behavior-Level Specification Alignment for Code Generation

Jul 2026 · 0 citations · 32 references
Computer Science

TL;DR

BeSpec is presented, a behavioral model-based approach to specification alignment that treats the task description as partial evidence about the intended behavior of the correct program, and first builds an explicit behavioral model, which are checkable properties that valid outputs must satisfy.

Abstract

LLMs have made substantial progress on automated code generation from natural-language descriptions of desired behavior (intent). Most existing methods improve generated programs through execution-guided code refinement: they generate a candidate solution, execute it, and patch the implementation using feedback, while leaving the underlying specification unchanged. This workflow implicitly assumes that the LLM's understanding of the intent is already correct and complete. In practice, however, intents are often ambiguous or underspecified. As a result, even a capable model may produce a correct implementation of the wrong intent, making specification mismatch a central bottleneck. This paper presents BeSpec, a behavioral model-based approach to specification alignment. BeSpec treats the task description as partial evidence about the intended behavior of the correct program. It first builds an explicit behavioral model, which are checkable properties that valid outputs must satisfy. BeSpec then generates candidate programs, executes them on probe inputs, and compares their observed behavior with the predicted behaviors. When observed behavior does not match the predicted behaviors, BeSpec either refines the specification or rejects the candidate program. We evaluate BeSpec with three LLMs on four benchmarks: CodeContests, xCodeEval, APPS, and the contamination-free LiveCodeBench. Against nine baselines, BeSpec achieves the highest Pass@1 and average pass rate across all settings, improving average Pass@1 over the strongest baseline by 8.1%--25.3% relative across the three LLMs. A failure analysis shows that after alignment, most remaining errors stem from algorithmic difficulty rather than misunderstood specifications, while ablation studies confirm that each major component of BeSpec contributes positively.

View source

Similar papers

Preprint Jul 2026

Teaching Code LLMs to Reason with Intermediate Formal Specifications

This paper introduces SpecCoder, a verification-guided CodeLLM training framework that learns from validated reference programs, behavior-changing mutants, and multi-turn specification-refinement traces, and improves checkpoint-specification quality over base CodeLLMs, and introduces HumanExec, a benchmark built from recent Codeforces competitive programming problems.

Minh Le-Anh, Cuong Chi Le, Tien N. Nguyen · 0 citations
Book Open access Jul 2026

From Syntactic Mimicry to Semantic Correctness: Behavioral Understanding in LLM Code Generation

This work addresses three interconnected challenges in building behaviorally-grounded code generation: retrieving not just what symbols are, but how they behave through usage patterns; adapting practices across contexts by separating behavioral intent from implementation details; and enforcing semantic properties during generation without prohibitive runtime costs.

A. Alam · 0 citations
Jul 2026

Bridging Behavior and Implementation: Automated Java Glue Code Generation for Behavior-Driven Development

Results show that behavior interpretation and project-aware context retrieval both contribute substantially to generation quality, and demonstrate that LLMs can effectively connect natural-language behavior specifications with project code and support specification-driven software development.

Xinyu Shi, Zhou Yang, An-Ran Chen · 0 citations

BRIDGE: Building Representations in Domain-Guided Program Synthesis

BRIDGE is presented, a structured prompting framework that decomposes verification into three interconnected domains: Code (implementations), Specifications (formal intent), and Theorem State-ments (constructive correctness claims), and elicits domain-specific intermediate reasoning to connect them.

Robert Joseph George, Carson Eisenach, Udaya Ghai et al. · 0 citations
Jul 2026

SpecFirst: Behavioral Specification Elicitation as a First-Class Step in Agent-Based Program Synthesis from Scratch

This work presents SpecFirst, a two-stage framework that forces the specification elicitation before code synthesis, and demonstrates that an explicit requirements-engineering phase is an effective paradigm for from-scratch program construction.

Yihao Chen, Shi Chang, Feng Lin et al. · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.