Position: Intelligent Coding Systems Should Write Programs with Justifications

Xiangzhe Xu, Shiwei Feng, Zian Su, Chengpeng Wang, Xiangyu ZhangarXiv 2025 · DOI

Abstract

AI coding assistants are transforming software development, yet their black-box nature poses significant risks. This paper argues that these systems must go beyond code generation to provide human-readable and formally verifiable justifications. We propose a neuro-symbolic framework that integrates domain knowledge into training and verifies justifications at inference time to ensure faithfulness and trust.

Introduction: The Trust Gap in AI-Generated Code

The rise of Large Language Models (LLMs) has ushered in a new era of software development. Tools like GitHub Copilot and ChatGPT are democratizing coding by allowing users to translate natural language prompts directly into executable source code. However, this shift introduces a critical challenge: trust. Because these models are probabilistic, they are prone to generating code that is buggy, insecure, or biased.

Currently, users—especially the growing population of non-expert developers—are forced to either blindly trust the AI's output or perform arduous manual verification. While "chain-of-thought" prompting can force an LLM to explain its reasoning, these explanations often lack "faithfulness." An LLM might provide a logically sound explanation for a code snippet that contains a hidden security vulnerability, effectively hallucinating a justification. Conversely, traditional formal verification methods offer mathematical rigor but are inaccessible to those without deep domain expertise. This paper identifies a critical gap: the need for explanations that are both easy for humans to understand and mathematically faithful to the actual code.

Proposed Methodology: A Neuro-Symbolic Pipeline

To address the justification gap, we propose a two-phase neuro-symbolic pipeline designed to align neural model outputs with symbolic programming constraints.

Phase 1: Training Guidance via Neuro-Symbolic RLHF

Standard Reinforcement Learning from Human Feedback (RLHF) focuses on making model outputs "helpful and harmless" based on human preference. We propose extending this by injecting programming language domain knowledge directly into the reward function. For instance, when a model generates code for a file upload server, the reward function should incorporate security standards like Common Weakness Enumerations (CWEs).

Figure 3: A neuro-symbolic training sample where domain knowledge informs the reward signal to ensure justifications are consistent with security constraints.

As shown in Figure 3, the system can provide positive reinforcement only when the model's justification explicitly addresses required security checks (e.g., validating file extensions). Furthermore, "metamorphic rewarding" can be used during training: if a code snippet is mutated (e.g., removing a security check), the training system checks if the model's justification consistently updates to flag the new code as unsafe.

Phase 2: Inference-Time Verification

To ensure that justifications remain faithful at runtime, we propose a verification engine. This involves using post-hoc explainability techniques, such as attention mapping, to link specific terms in the natural language justification to concrete variables and entities within the generated code. These links are then translated into "neural semantic rules" which can be automatically cross-referenced against the program's actual formal semantics. If the text claims the code is "safe" while the formal analysis detects an unvalidated write, the system can flag the discrepancy to the user.

Key Insights: Bridging the Gap

The core of our position is that an effective justification must satisfy two primary properties: Cognitive Alignment (written in natural language that aligns with human reasoning) and Semantic Faithfulness (automatically verifiable against the actual execution logic).

Figure 5: The spectrum of justification formats, ranging from natural language to programming language.

As illustrated in Figure 5, existing methods fall on a spectrum. Natural language explanations (post-hoc explainability) are easy to read but hard to verify. Static analysis and formal proofs are highly verifiable but difficult for humans to parse. Neuro-symbolic approaches aim for the "Goldilocks zone," combining the flexibility of neural networks with the rigorous constraints of symbolic logic.

Conclusion and Future Work

This framework represents a call to action for the AI and Programming Languages (PL) communities to collaborate on making intelligent coding systems more transparent. While the proposed pipeline offers a path forward, significant technical hurdles remain. Current post-hoc explainability techniques are often limited to simple, localized code snippets. Scaling these methods to handle complex, multi-file software projects while maintaining high-level natural language coherence is a major open research challenge. By prioritizing justifications alongside code generation, we can build a future where AI-assisted programming is not just powerful, but provably trustworthy.

Summary updated

BibTeX
@misc{xu2025position,
  author = {Xiangzhe Xu and Shiwei Feng and Zian Su and Chengpeng Wang and Xiangyu Zhang},
  title = {{Position: Intelligent Coding Systems Should Write Programs with Justifications}},
  year = {2025},
  eprint = {2508.06017},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2508.06017},
}
Figure