NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

CoCoST: Automatic Complex Code Generation with Online Searching and Correctness Testing

Xinyi He, Jiaru Zou, Yun Lin, Mengyu Zhou, Shi Han, Zejian Yuan, Dongmei Zhang

Introduction

Large Language Models (LLMs) excel at generating simple code snippets but often struggle with complex, production-grade tasks involving intricate data structures like Tensors or DataFrames. These difficulties arise from stale knowledge in training data, the absence of pre-written test suites in real-world environments, and "hidden bugs"—logical errors that do not cause crashes but result in incorrect outputs. CoCoST (Automatic Complex Code Generation with Online Searching and Correctness Testing) is a framework designed to overcome these hurdles by mimicking the human developer workflow.

The CoCoST Framework

CoCoST introduces a two-stage pipeline that integrates real-time information retrieval with iterative logical verification.

The CoCoST two-stage pipeline: Retrieval via Planning and Correctness-Based Refinement.

Retrieval via Planning

Instead of simple prompt-based searching, CoCoST employs a planning phase where the LLM creates a multi-step strategy. It identifies specific knowledge gaps and generates targeted search queries for platforms like StackOverflow and official documentation. This structured approach ensures the model has access to the most current information, reducing hallucinations.

Correctness-Based Refinement

The framework's core innovation is its refinement loop. The LLM generates test inputs and executes the code. To allow the model to "understand" complex outputs, CoCoST uses serialization:

  • Data Summarization: Large matrices are represented by statistical metadata (shape, min, max).
  • Visual Output: Matplotlib plots are converted to text-based SVG format. By comparing these serialized results against the problem requirements, the LLM can identify and fix logical errors that standard debugging tools, which only react to execution crashes, would miss.

Evaluation and Results

The researchers evaluated CoCoST on two challenging benchmarks: DS-1000, which focuses on data science libraries (NumPy, Pandas, PyTorch), and ClassEval, which tests class-level logic consistency.

Performance comparison on the DS-1000 benchmark across different perturbation types.

On the DS-1000 benchmark, CoCoST achieved an accuracy of 68.0%, outperforming the base GPT-4 model by 7.8% and the previous state-of-the-art (SELFEVOLVE) by 10.9%. Notably, in the "Diff-Rewrite" category—representing the most complex logical transformations—CoCoST outperformed competing methods by nearly 20%. Similarly, on ClassEval, the framework showed an average improvement of 9.47%, proving its effectiveness across both functional and object-oriented programming paradigms.

Conclusion and Future Work

CoCoST demonstrates that the key to improving AI-driven code generation lies in providing models with the same tools humans use: real-time search and a feedback-driven execution environment. While the system faces practical constraints such as latency and API dependency, it significantly advances the state of the art in handling complex coding tasks. Future research will focus on refining query generation and addressing the "reasoning ceiling" that persists in current models.

Summary updated

BibTeX
@inproceedings{he2024cocost,
  author = {Xinyi He and Jiaru Zou and Yun Lin and Mengyu Zhou and Shi Han and Zejian Yuan and Dongmei Zhang},
  title = {{CoCoST: Automatic Complex Code Generation with Online Searching and Correctness Testing}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.emnlp-main.1082},
}
Figure