CodeGenWrangler: Data Wrangling task automation using Code-Generating Models

Ashlesha Akella, Abhijit Manatkar, Krishnasuri Narayanam, Sameep MehtaNAACL 2025

Introduction

CodeGenWrangler automates tabular data wrangling by leveraging Large Language Models (LLMs) to generate executable Python code rather than processing data row-by-row. This approach significantly reduces computational costs—by approximately 10x—while outperforming traditional row-wise inference through the integration of Retrieval-Augmented Generation (RAG) and iterative prompt optimization.

The Data Wrangling Challenge

Data wrangling, which includes cleaning, imputing missing values, and correcting errors, remains a major bottleneck in data science. Traditional statistical methods are efficient but often lack the semantic "common sense" required for complex tasks, such as identifying a city based on a zip code. Conversely, recent attempts to apply LLMs to these tasks have encountered two primary obstacles:

  1. Scalability: Row-by-row LLM API calls are prohibitively expensive and slow for industrial-scale datasets.
  2. Knowledge Gaps: LLMs may rely on outdated internal knowledge or lack the specific enterprise context necessary for accurate domain-specific cleaning.

CodeGenWrangler bridges this gap by treating the LLM as a "programmer" that writes a cleaning script for the entire dataset, rather than a "clerk" processing entries individually.

System Architecture and Methodology

The CodeGenWrangler pipeline transforms raw, messy data into clean, executable code through several key stages:

  • Dataset Filtering: A Histogram-based Gradient Boosting model identifies relevant columns for the target task, filtering out noise to focus the LLM.
  • Knowledge Retrieval (RAG): The system utilizes two modules: a memory-independent module for internal dataset patterns and a memory-dependent module that retrieves context from external reference tables (e.g., master country code lists) using semantic similarity.
  • Iterative Prompt Optimization: Instead of a single prompt, the system employs a feedback loop. It generates code, tests it against a validation data slice, and feeds the best-performing logic back into the next prompt for refinement.
  • Ensemble Voting: To ensure robustness, multiple code snippets are generated. These snippets "vote" on the correct value for every row, mitigating the risk of individual script bugs.
The CodeGenWrangler pipeline including filtering, RAG, and iterative optimization.

Experimental Evaluation

The researchers evaluated CodeGenWrangler using 21 diverse datasets from Kaggle and OpenML, covering domains such as Airlines (continent/country code imputation), Fortune 1000 (industry classification errors), E-commerce (product category trees), and Customer Support (ticket categorization).

Key Results and Insights

Efficiency and Cost Reduction

The primary advantage of CodeGenWrangler is its efficiency. By representing data patterns as concise Python rules, the system executes code locally in milliseconds rather than relying on repeated, expensive LLM inferences. This resulted in a reduction of LLM calls by a factor of 10 compared to row-wise methods.

Comparison of LLM call counts between row-level processing and CodeGenWrangler across various datasets.

Accuracy and Logic

On knowledge-dependent tasks, CodeGenWrangler consistently outperformed row-wise baselines, often achieving near-perfect accuracy (0.98-1.00). The system successfully generated complex nested logic to handle intricate taxonomies that simple statistical models cannot address. Furthermore, the iterative optimization process showed clear performance gains; while simple tasks converged in under 10 iterations, complex semantic tasks continued to improve for up to 40 iterations.

Limitations and Future Work

While highly effective for imputation, the system faces hurdles in Error Detection (ED), as errors like typos are often random and lack the logical patterns easily captured by Python functions. Additionally, the code-generation approach is less effective for datasets requiring deep probabilistic reasoning without clear column dependencies. Future work will focus on expanding the system to support more diverse tasks and multiple programming languages.

Summary updated

BibTeX
@inproceedings{akella2025codegenwrangler,
  author = {Ashlesha Akella and Abhijit Manatkar and Krishnasuri Narayanam and Sameep Mehta},
  title = {{CodeGenWrangler: Data Wrangling task automation using Code-Generating Models}},
  booktitle = {Conference of the North American Chapter of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.naacl-industry.70},
}
Figure