2601.19106v1 Jan 27, 2026 cs.SE

결정론적 AST 분석을 통한 LLM 생성 코드의 환각 현상 감지 및 수정

Detecting and Correcting Hallucinations in LLM-Generated Code via Deterministic AST Analysis

Dipin Khati
Dipin Khati
Citations: 36
h-index: 3
Daniel Rodríguez-Cárdenas
Daniel Rodríguez-Cárdenas
Citations: 72
h-index: 5
Denys Poshyvanyk
Denys Poshyvanyk
Citations: 159
h-index: 8
Paul Pantzer
Paul Pantzer
Citations: 0
h-index: 0

코드 생성을 위한 대규모 언어 모델(LLM)은 생산성을 향상시키지만, 종종 지식 충돌로 인한 환각(KCH, Knowledge Conflicting Hallucinations)을 발생시켜, 존재하지 않는 API 매개변수와 같은 미묘한 의미 오류를 야기하며, 이는 린터(linter)를 회피하고 런타임 오류를 유발합니다. 기존의 제약 기반 디코딩 또는 비결정론적 LLM-in-the-loop 수정 방법은 이러한 오류에 대해 종종 신뢰성이 떨어집니다. 본 논문에서는 결정론적인 정적 분석 프레임워크가 KCH를 신뢰성 있게 감지하고 자동으로 수정할 수 있는지 조사합니다. 우리는 생성된 코드를 추상 구문 트리(AST)로 파싱하고 라이브러리 분석을 통해 동적으로 생성된 지식 기반(KB)에 대해 유효성을 검사하는 후처리 프레임워크를 제안합니다. 이 실행하지 않는 접근 방식은 결정론적인 규칙을 사용하여 API 및 식별자 수준의 충돌을 찾아 수정합니다. 수동으로 큐레이션된 200개의 Python 코드 조각 데이터 세트에서, 우리의 프레임워크는 100%의 정확도와 87.6%의 재현율(0.934 F1 점수)로 KCH를 감지했으며, 식별된 모든 환각의 77.0%를 성공적으로 자동으로 수정했습니다. 우리의 연구 결과는 이 결정론적인 후처리 접근 방식이 확률 기반 수정의 신뢰성 있는 대안이 될 수 있으며, 신뢰할 수 있는 코드 생성으로 이어지는 명확한 경로를 제시한다는 것을 보여줍니다.

Original Abstract

Large Language Models (LLMs) for code generation boost productivity but frequently introduce Knowledge Conflicting Hallucinations (KCHs), subtle, semantic errors, such as non-existent API parameters, that evade linters and cause runtime failures. Existing mitigations like constrained decoding or non-deterministic LLM-in-the-loop repair are often unreliable for these errors. This paper investigates whether a deterministic, static-analysis framework can reliably detect \textit{and} auto-correct KCHs. We propose a post-processing framework that parses generated code into an Abstract Syntax Tree (AST) and validates it against a dynamically-generated Knowledge Base (KB) built via library introspection. This non-executing approach uses deterministic rules to find and fix both API and identifier-level conflicts. On a manually-curated dataset of 200 Python snippets, our framework detected KCHs with 100\% precision and 87.6\% recall (0.934 F1-score), and successfully auto-corrected 77.0\% of all identified hallucinations. Our findings demonstrate that this deterministic post-processing approach is a viable and reliable alternative to probabilistic repair, offering a clear path toward trustworthy code generation.

0 Citations
0 Influential
4 Altmetric
20.0 Score

No Analysis Report Yet

This paper hasn't been analyzed by Gemini yet.

댓글

댓글을 작성하려면 로그인하세요.

아직 댓글이 없습니다. 첫 번째 댓글을 남겨보세요!