FaithfulPersona: Balancing Faithfulness and Personalization in Code Explanations through Self-Critique

Kyumin LeeOpenReview 2025

Abstract

Code explanations are crucial in real-world life, from educating students to aligning technical projects with business goals. However, existing approaches face challenges balancing faithfulness to the original code and personalization for diverse user needs. This paper addresses these challenges by introducing a novel benchmark and method for generating faithful personalized code explanations. Our benchmark, FaithfulPersonaCodeX, incorporates code samples and user profiles, employing various evaluation metrics to evaluate both faithfulness and personalization. We propose DISCO, a new method that uses a self-critique mechanism and two-stage optimization to balance faithfulness and personalization in code explanations, addressing the limitations of current large language model approaches. Our proposed model, DISCO, achieves a notable 3.7% improvement in Pass@5 compared to the strong baseline method, Self-Consistency, while maintaining high personalization with a 61.08% win rate in the LLM-as-a-Judge evaluation, effectively balancing faithfulness and user-specific needs in code explanations.

Introduction

Generating code explanations that are both technically accurate ("faithful") and tailored to a specific user's expertise ("personalized") is a difficult balancing act for Large Language Models (LLMs). While LLMs excel at summarization, they often suffer from a faithfulness gap, where explanations fail to capture actual execution logic, and a personalization gap, where a "one-size-fits-all" approach fails to meet the needs of diverse users—from beginners to experts.

Current benchmarks often rely on static ground-truth summaries, such as code comments, which frequently lack depth or fail to explain the "why" behind algorithmic choices. Furthermore, the absence of user-specific context in these benchmarks makes it difficult to measure an AI's adaptability. To address these issues, we introduce DISCO, a dual-stage optimization method, and FaithfulPersonaCodeX, a dynamic benchmark for profile-based evaluation.

Methodology: The DISCO Framework

The authors propose DISCO (Dual-objective Iterative Self-Critiquing Optimization). Rather than attempting to optimize for accuracy and personalization simultaneously—which often leads to "hallucinated" personalization that contradicts code logic—DISCO decouples the task into two sequential stages.

The DISCO framework: A two-stage iterative refinement process for faithfulness and personalization.

Stage 1: Faithfulness Refinement

The model first generates an initial explanation. To verify its accuracy, a separate LLM attempts to reconstruct the original code based solely on that explanation. If the reconstructed code fails public test cases, a "Failure Analysis" is generated. The explanation is then iteratively refined until the code it describes is functionally correct. This "debug" loop ensures the final text is technically grounded.

Stage 2: Personalization Refinement

Once a faithful explanation is established, it is tailored to a specific user profile. These profiles are extracted from real-world Stack Overflow histories to reflect genuine user interests and skill levels. A "Role-Playing LLM" simulates the target user, providing feedback and ratings to ensure the explanation aligns with the persona's background.

The FaithfulPersonaCodeX Benchmark

To evaluate these methods, we developed FaithfulPersonaCodeX. This benchmark moves away from static references toward a more rigorous, execution-based evaluation.

Components of the FaithfulPersonaCodeX benchmark, including code, problem context, and user profiles.

The benchmark consists of:

  • 169 Code Samples: Sourced from CodeContests, featuring complex competitive programming logic.
  • 10 Distinct User Profiles: Derived from Stack Overflow to capture diverse technical backgrounds, such as image processing or data analysis.
  • Multi-faceted Metrics: Faithfulness is measured via Pass@k (code reconstruction success), while personalization is assessed using LLM-as-a-Judge, ROUGE-L, and Word Overlap.

Results and Discussion

DISCO was evaluated using GPT-3.5 and Claude 3 Sonnet against strong baselines like Self-Consistency.

  • Improved Faithfulness: DISCO achieved a 3.7% absolute improvement in Pass@5 over the Self-Consistency baseline, outperforming specialized commercial tools.
  • Superior Personalization: In head-to-head "LLM-as-a-Judge" evaluations, DISCO won 61.08% of the time.
  • Human Validation: Professional software engineers rated DISCO higher in usefulness, clarity, and overall understanding.

A key insight from this work is that reference-free evaluation via code reconstruction eliminates the need for expensive, subjective human-written "perfect" explanations. Furthermore, the sequential optimization approach prevents the model from sacrificing logic for the sake of relatable metaphors.

Conclusion and Future Work

While DISCO shows significant promise, its performance is tied to the reasoning capabilities of the underlying LLM backbone. Future work will involve expanding the benchmark to include more diverse code sources beyond competitive programming, such as enterprise-level software, and exploring applications in real-time AI tutoring systems. By prioritizing faithfulness as a foundation for personalization, DISCO provides a robust path forward for AI-driven technical communication.

Summary updated

BibTeX
@misc{lee2025faithfulpersona,
  author = {Kyumin Lee},
  title = {{FaithfulPersona: Balancing Faithfulness and Personalization in Code Explanations through Self-Critique}},
  year = {2025},
  url = {https://openreview.net/forum?id=SkvtO9Cohe},
  howpublished = {OpenReview},
}
Figure