Multi-Objective Agentic Rewrites for Unstructured Data Processing

Lindsey Linxi Wei, Shreya Shankar, Sepanta Zeighami, Yeounoh Chung, Fatma Özcan, Aditya G. Parameswaran · DOI

Abstract

Processing unstructured data with Large Language Model (LLM) pipelines is often expensive and unreliable. Existing optimizers typically focus on either cost or accuracy in isolation, failing to account for the complex, non-compositional interactions between semantic operators. We present MOAR (Multi-Objective Agentic Rewrites), a query optimizer that jointly optimizes for cost and accuracy. MOAR utilizes an LLM agent to explore a vast search space of pipeline configurations using over 30 rewrite directives, including code synthesis and operator fusion. By employing a multi-armed bandit search algorithm, MOAR identifies high-accuracy, cost-effective pipelines, outperforming state-of-the-art optimizers by an average of 27% in accuracy while significantly reducing operational costs.

Introduction: The Challenge of LLM Pipeline Optimization

As developers increasingly adopt declarative systems for unstructured data processing, they build pipelines from "semantic operators"—tasks like mapping or filtering described in natural language. However, these pipelines face two major hurdles: high operational costs and the risk of hallucinations.

Traditional database optimization techniques rely on the principle of optimal substructure, assuming that the best global plan is composed of the best local sub-plans. This assumption breaks down in LLM-powered pipelines. An upstream operator that produces concise output might seem suboptimal in isolation but could drastically improve a downstream operator's performance by reducing noise. Consequently, optimizers must evaluate the entire pipeline globally, balancing cost and accuracy across a massive, non-linear search space.

The MOAR Framework

MOAR addresses these challenges through a combination of expanded rewrite capabilities and a sophisticated global search mechanism.

System Architecture

The MOAR system operates as an iterative loop. It starts with a user-defined pipeline and uses an LLM agent to propose and evaluate rewrites. The system maintains a state including model statistics, directive performance, and a Pareto frontier of evaluated pipelines.

The MOAR system architecture, illustrating the iterative loop of selection, rewriting, and evaluation by an LLM agent.

Rewrite Directives and Search Tree

MOAR extends the DocETL system with a library of over 30 abstract transformation rules. These include:

  • Operator Fusion: Combining multiple LLM steps into one to reduce overhead.
  • Code Synthesis: Swapping expensive LLM calls for synthesized Python or regex to handle deterministic tasks.
  • Data Decomposition: Chunking or sampling documents to focus LLM attention.

The search space is modeled as a tree where each node represents a complete pipeline and edges represent applied rewrites. To navigate this tree efficiently, MOAR uses a variant of the Upper Confidence Bound (UCB) algorithm. It prioritizes pipelines that offer the highest marginal accuracy contribution to the Pareto frontier. To ensure deep exploration, MOAR employs "progressive widening," preventing the agent from over-optimizing a single branch.

An example search tree generated by MOAR, showing how different rewrites (e.g., model changes, chunking, prompt improvements) impact F1 scores and costs.

Experimental Evaluation

MOAR was evaluated across six diverse real-world workloads, including legal contract extraction (CUAD), biomedical data extraction (Biodex), and medical error detection (MEDEC).

Key Results

  • Superior Accuracy: MOAR discovered the highest-accuracy pipeline for every workload, achieving 27% higher accuracy on average than the next-best optimizer, ABACUS.
  • Cost Efficiency: MOAR matched the peak accuracy of competing systems at approximately 55% of their cost. In extreme cases, such as the Game Reviews dataset, it achieved baseline-level accuracy at just 0.3% of the cost.
  • Pareto Dominance: On 4 out of 6 workloads, MOAR's discovered pipelines completely dominated the cost-accuracy Pareto frontier, offering a wide range of optimal configurations for different budget constraints.

Discussion and Insights

The evaluation revealed several critical insights into effective LLM pipeline design:

  1. Code-LLM Hybridization: Nearly half of the top-performing pipelines utilized agent-authored Python code. Using code for deterministic filtering or extraction significantly reduces the token volume processed by LLMs, lowering costs and improving focus.
  2. Model Heterogeneity: Optimal pipelines rarely rely on a single model. MOAR often mixes models (e.g., using specialized models for simple extractions and frontier models for complex reasoning) to balance performance and price.
  3. Decomposition over "Mega-prompts": High-accuracy pipelines typically used 2.3× more operators than the original user-written versions. Breaking tasks into specialized steps (chunking, filtering, mapping) consistently outperformed single-step "mega-prompt" approaches.

Conclusion

MOAR demonstrates that agentic, multi-objective optimization can significantly enhance the performance and affordability of LLM-powered data pipelines. While the optimization process itself incurs a one-time cost, the resulting pipelines offer substantial long-term savings and accuracy gains. Future work will focus on reducing the cost of the optimizer by using smaller specialized models for rewriting and developing better cost/accuracy estimation models to reduce the need for physical execution during the search phase.

Summary updated

BibTeX
@misc{wei2025multi,
  author = {Lindsey Linxi Wei and Shreya Shankar and Sepanta Zeighami and Yeounoh Chung and Fatma Özcan and Aditya G. Parameswaran},
  title = {{Multi-Objective Agentic Rewrites for Unstructured Data Processing}},
  year = {2025},
  eprint = {2512.02289},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2512.02289},
}
Figure