A Comparative Study of DSL Code Generation: Fine-Tuning vs. Optimized Retrieval Augmentation
On the map: Retrieval-augmented generation → RAG for code
Abstract (arXiv)
Natural Language to Code Generation has made significant progress in recent years with the advent of Large Language Models(LLMs). While generation for general-purpose languages like C, C++, and Python has improved significantly, LLMs struggle with custom function names in Domain Specific Languages or DSLs. This leads to higher hallucination rates and syntax errors, specially for DSLs having a high number of custom function names. Additionally, constant updates to function names add to the challenge as LLMs need to stay up-to-date. In this paper, we present optimizations for using Retrieval Augmented Generation (or RAG) with LLMs for DSL generation along with an ablation study comparing these strategies. We generated a train as well as test dataset with a DSL to represent automation tasks across roughly 700 APIs in public domain. We used the training dataset to fine-tune a Codex model for this DSL. Our results showed that the fine-tuned model scored the best on code similarity metric. With our RAG optimizations, we achieved parity for similarity metric. The compilation rate, however, showed that both the models still got the syntax wrong many times, with RAG-based method being 2 pts better. Conversely, hallucination rate for RAG model lagged by 1 pt for API names and by 2 pts for API parameter keys. We conclude that an optimized RAG model can match the quality of fine-tuned models and offer advantages for new, unseen APIs.
Key facts. Cited by 8 papers in the map (data through 7 Oct 2026). Placed in RAG for code, one of 15 directions in Retrieval-augmented generation. Builds on 8 of its 21 references that are in the map. First posted on arXiv 3 Jul 2024.
Builds on
8 of 21 references.
References · 8
- 2022Large Language Models are Zero-Shot Reasonerscited by 4,323
- 2023Toolformer: Language Models Can Teach Themselves to Use Toolscited by 4,072
- 2022Solving Quantitative Reasoning Problems with Language Modelscited by 1,359
- 2022Unnatural Instructions: Tuning Language Models with (Almost) No Human Laborcited by 395
- 2023TaskMatrix.AI: Completing Tasks by Connecting Foundation Models with Millions of APIscited by 184
- 2017RobustFill: Neural Program Learning under Noisy I/Ocited by 124
- 2021Jigsaw: Large Language Models meet Program Synthesiscited by 103
- 2023Improving ChatGPT Prompt for Code Generationcited by 28
Built on by
Citing papers per year: 2024: 2; 2025: 3; 2026: 3.
8 papers.
- 2025Type-Constrained Code Generation with Language Modelscited by 32
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtrackingcited by 28
- 2024Design2GarmentCode: Turning Design Concepts to Tangible Garments Through Program Synthesiscited by 17
- 2025Fine-Tune an SLM or Prompt an LLM? The Case of Generating Low-Code Workflowscited by 6
- 2025StarFlow: Generating Structured Workflow Outputs From Sketch Imagescited by 2
- 2026SLM Finetuning for Natural Language to Domain Specific Code Generation in Productioncited by 0
- 2026Leveraging LLMs for Multi-File DSL Code Generation: An Industrial Case Studycited by 0
- 2026Workflow as Knowledge: Semantic Persistence for LLM-Mediated Workflowscited by 0
- 2026Workflow as Knowledge: Semantic Persistence for LLM-Mediated Workflows9 Jul 2026
- 2026Leveraging LLMs for Multi-File DSL Code Generation: An Industrial Case Study27 Apr 2026
- 2026SLM Finetuning for Natural Language to Domain Specific Code Generation in Production10 Apr 2026
- 2025Fine-Tune an SLM or Prompt an LLM? The Case of Generating Low-Code Workflows30 May 2025
- 2025Type-Constrained Code Generation with Language Models12 Apr 2025
- 2025StarFlow: Generating Structured Workflow Outputs From Sketch Images27 Mar 2025
- 2024Design2GarmentCode: Turning Design Concepts to Tangible Garments Through Program Synthesis11 Dec 2024
- 2024IterGen: Iterative Semantic-aware Structured LLM Generation with Backtracking9 Oct 2024
Similar, not cited
Close in wording, no citation either way
- 2024Plan with Code: Comparing approaches for robust NL to DSL generation
- 2026Text2DSL: LLM-Based Code Generation for Domain-Specific Languages
- 2026Are you Synthesizing or Recalling? Evaluating LLMs on Algorithmic Code Retrieval
- 2025When LLMs Meet API Documentation: Can Retrieval Augmentation Aid Code Generation Just as It Helps Developers?
- 2024CodeRAG-Bench: Can Retrieval Augment Code Generation?
- 2025Evaluating Large Language Models for Functional and Maintainable Code in Industrial Settings: A Case Study at ASML
- 2025An Empirical Study of Retrieval-Augmented Code Generation: Challenges and Opportunities
- 2025Beyond Synthetic Benchmarks: Evaluating LLM Performance on Real-World Class-Level Code Generation