Skip to main content
QUICK REVIEW

[Paper Review] SQL-Commenter: Aligning Large Language Models for SQL Comment Generation with Direct Preference Optimization

Lei Yu, Peng Wang|arXiv (Cornell University)|Mar 19, 2026
Natural Language Processing TechniquesComputer Science0 citations
TL;DR

SQL-Commenter enhances SQL comment generation by combining continual pre-training, supervised fine-tuning, and direct preference optimization (DPO) on LLaMA-3.1-8B, achieving state-of-the-art results on Spider and Bird benchmarks and outperforming baselines in human evaluation.

ABSTRACT

SQL query comprehension is a significant challenge due to complex syntax, diverse join types, and deep nesting. Many queries lack adequate comments, severely hindering code readability, maintainability, and knowledge transfer. Automated SQL comment generation faces two main challenges: limited datasets that inadequately represent complex real-world queries, and Large Language Models' (LLMs) insufficient understanding of SQL-specific semantics. Our empirical analysis shows that even after continual pre-training and supervised fine-tuning, LLMs struggle with complex SQL semantics, yielding inaccurate comments. To address this, we propose SQL-Commenter, an advanced method based on LLaMA-3.1-8B. We first construct a comprehensive dataset of complex SQL queries with expert-verified comments. Next, we perform continual pre-training on a large SQL corpus to enhance the LLM's syntax and semantic understanding, followed by supervised fine-tuning. Finally, we introduce Direct Preference Optimization (DPO) using human feedback. SQL-Commenter utilizes a preference-based loss function to favor preferred outputs, enhancing fine-grained semantic learning and context-dependent quality assessment. Evaluated on the Spider and Bird benchmarks, SQL-Commenter significantly outperforms state-of-the-art baselines. On average, it surpasses the strongest baseline (Qwen3-14B) by 9.29, 4.99, and 13.23 percentage points on BLEU-4, METEOR, and ROUGE-L, respectively. Moreover, human evaluation demonstrates the superior quality of comments generated by SQL-Commenter in terms of correctness, completeness, and naturalness.

Motivation & Objective

  • Address the challenge of generating high-quality, technically accurate SQL comments for complex queries in real-world analytics and legacy systems.
  • Create a high-quality, expert-verified dataset of complex SQL queries with detailed comments drawn from Spider and Bird benchmarks.
  • Enhance LLM understanding of SQL syntax/semantics through continual pre-training on a large SQL corpus.
  • Improve comment quality via supervised fine-tuning on a specialized SQL-comment dataset and direct preference optimization using human feedback.
  • Demonstrate state-of-the-art performance on automatic metrics and human evaluation, and release datasets and code publicly.

Proposed method

  • Construct a large, expert-verified dataset of complex SQL queries with detailed comments sourced from Spider and Bird benchmarks.
  • Perform continual pre-training (CPT) of LLaMA-3.1-8B on ~1.2M SQL queries plus general-domain data to improve SQL comprehension.
  • Apply supervised fine-tuning (SFT) on ~15,071 ⟨SQL, Comment⟩ pairs to teach detailed, technically accurate explanations.
  • Introduce Direct Preference Optimization (DPO) using preferred/non-preferred comment pairs to align outputs with developer preferences.
  • Use a two-stage data construction: (1) generate machine-assisted comments via DeepSeek-V3.1 and expert refinement; (2) create preferred/rejected pairs via multi-strategy negative sampling for DPO.
  • Evaluate on Spider and Bird benchmarks with BLEU-4, METEOR, and ROUGE-L, plus human evaluation on correctness, completeness, and naturalness.
Figure 1. The Motivation of our SQL-Commenter.
Figure 1. The Motivation of our SQL-Commenter.

Experimental results

Research questions

  • RQ1RQ1: How does SQL-Commenter perform on SQL comment generation compared to state-of-the-art baselines on Spider and Bird?
  • RQ2RQ2: How effective are the CPT, SFT, and DPO components individually and in combination?
  • RQ3RQ3: How do human evaluators rate the generated comments in terms of correctness, completeness, and naturalness?
  • RQ4RQ4: What are the common failure modes and potential directions for improvement?

Key findings

  • SQL-Commenter achieves state-of-the-art automatic metric scores on Spider and Bird dev/test sets compared with strong baselines.
  • On Spider dev, it reaches BLEU-4 36.95, METEOR 58.37, ROUGE-L 57.17, outperforming the strongest baseline by substantial margins.
  • On Spider test, it achieves BLEU-4 36.37, METEOR 57.76, ROUGE-L 56.48, with notable improvements over baselines.
  • On Bird dev, it attains BLEU-4 35.09, METEOR 55.91, ROUGE-L 56.74, exceeding baselines by large margins.
  • Human evaluation shows SQL-Commenter’s comments are more correct, complete, and natural than baselines.
  • First to introduce Direct Preference Optimization (DPO) for SQL comment generation, with public release of datasets and code.
Figure 2. The Overview of our SQL-Commenter.
Figure 2. The Overview of our SQL-Commenter.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.