The ability of large language models to generate computer code from natural language (NL) prompts has revolutionized the programming domain. Most contemporary models however can only generate code for seen libraries and function calls, and struggle when they encounter any of the new libraries or functions that are constantly being introduced. A human programmer facing such a challenge would typically research and retrieve user manuals and other relevant documents to familiarize themselves with the new library/function — could LLMs be taught to do the same?
In the new paper DocPrompting: Generating Code by Retrieving the Docs, a research team from Carnegie Mellon University and Inspired Cognition presents DocPrompting, a novel NL-to-code generation approach. Tasked with generating code to unseen functions or libraries from an NL intent, DocPrompting retrieves corresponding code documentation to enable the model to learn to perform the task.

DocPrompting is inspired by programmers’ use of manuals and documentation when encountering unseen/unused functions or libraries. The approach first learns to retrieve relevant documents from an external documentation pool, then learns to generate code using prompts based on the information it gleaned from the documents.

The documentation pool can be regularly updated with new content to enable DocPrompting to generate unseen and unused functions and libraries without requiring any costly retraining of model components. DocPrompting is also a general method — it can be applied to any programming language and is not bounded to the underlying neural model, and can be instantiated with any base retriever and generator.


In their empirical study, the team evaluated DocPrompting on two NL-to-code tasks and benchmarks: shell scripting and Python programming. In the shell scripting task, DocPrompting consistently improved on the base model; while In Python programming, CodeT5+DocPrompting performed exceptionally well on unseen functions and achieved a 1.65 BLEU score improvement over the state-of-the-art result.
This work opens a promising new direction for the evolution of code generation. The team says that, to their best knowledge, DocPrompting is the first approach to explicitly and effectively leverage documentation for NL-to-code tasks.
The code is available on the project’s GitHub. The paper DocPrompting: Generating Code by Retrieving the Docs is on arXiv.
Author: Hecate He | Editor: Michael Sarazen

We know you don’t want to miss any news or research breakthroughs. Subscribe to our popular newsletter Synced Global AI Weekly to get weekly AI updates.

DocPrompting from CMU and Inspired Cognition is a clever way to improve code generation by retrieving from documentation. Thanks for the clear summary.
Retrieving documentation before asking the model to use an unfamiliar library is a useful distinction. I’d evaluate the retrieval step separately: check whether it finds the exact API entry and version before judging whether the generated code is correct.
Retrieving live documentation before generating code is such a practical way to keep LLMs grounded when APIs evolve rapidly. We see a similar need for clear structured prompts when building creative workflows on AI tools. Thanks for breaking down the DocPrompting paper so clearly!
The comparison to a human programmer pulling up the manual is the right framing — most code models fail not because they can’t write syntax but because they’ve never seen the library. I remember a paper summary I read where retrieval alone closed a surprising chunk of the gap. Curious how DocPrompting handles versioned docs where the API changed last week.
Retrieving the relevant documentation before generating code is the fix that should have shipped years earlier, and the ablation on doc quality is the part worth reading twice. CMU with Inspired Cognition is a sensible pairing for this. I have notes on retrieval pipelines from a side project that hit the same wall.
DocPrompting’s focus on retrieving live, versioned docs before code generation is spot-on—especially when APIs change fast. I’ve hit that wall too with creative AI workflows. For similar grounding in structured prompts, check out https.
Great insights on improving code generation! It’s fascinating how technology evolves. I’ve been exploring I Ching Online lately for some personal guidance – it’s quite interesting how AI can enhance traditional practices.
Thanks for sharing this interesting development! It’s amazing how these models are evolving. For anyone looking to explore more complex guidance, I’ve found I Ching Online to be incredibly insightful and helpful.
Really interesting read on how models improve with DocPrompting. I find Krillion People great for expanding my knowledge, which can definitely help in coding too!
Retrieving docs instead of fine-tuning is the cheap half of DocPrompting, but the interesting claim is that the model learns to pick the relevant doc, which is exactly where most code assistants stumble on unseen libraries. Testing on functions the model never saw is what makes the result worth reading. Found it with [[that little cat page]] in another tab and a long compile running. More details: Pet the Cat Online.
What stands out to me is the decision to keep the documentation pool outside the model entirely — treating docs as a swappable index rather than something baked into weights means the retrieval quality becomes the real bottleneck, and I’d want to see how much of DocPrompting’s gain survives when the retriever is swapped for something weaker. Also worth noting the docs it pulls are often prose written for humans, full of prose caveats and deprecation notes the model has to filter out. Off the topic of the paper, but anyone iterating on short clips might get something out of the web app I’ve been leaning on for quick 30-second drafts with audio already in sync.