[ICRA 2025] Modernizing Robotics Infrastructure: Using LLMs to Bridge C++ and Python with Nanobind
Python Bindings for a Large C++ Robotics Library: The Case of OMPL
The paper introduces a human-in-the-loop workflow using Large Language Models (LLMs) to generate Python bindings for the Open Motion Planning Library (OMPL) using nanobind. By mirroring C++ structures and leveraging LLMs for boilerplate generation, the authors successfully migrated a complex robotics codebase from legacy Boost.Python to a modern, high-performance interface.
TL;DR
Researchers have developed a human-in-the-loop workflow using LLMs to generate high-performance Python bindings for the Open Motion Planning Library (OMPL). By moving from legacy Boost.Python to nanobind, they achieved better performance and maintainability while documenting the specific "prompt recipes" needed to overcome LLM hallucinations in C++ systems programming.
Problem & Motivation: The "Binding Burden"
In modern robotics, C++ remains the king of performance-critical backends (motion planning, physics), while Python is the lingua franca for machine learning and rapid prototyping. The bridge between them—Python bindings—is often the weakest link.
For OMPL, a library with over 300 classes, the existing bindings relied on Py++, a tool essentially "frozen in time" that fails on modern compilers like GCC 15.2. Manually rewriting these bindings is a Herculean task for maintainers. The authors asked: Can we use LLMs to automate the boilerplate while letting experts handle the architectural nuance?
Methodology: Mirroring and Scaffolding
The authors argue that "one-shot" LLM generation for an entire library is a recipe for disaster. Instead, they proposed a structured pipeline:
- Workspace Mirroring: The C++ source layout (e.g.,
src/ompl/base/) is mirrored in the binding directory. This provides clear context for both humans and AI. - Expert Scaffolding: Humans create the initial file structure and CMake configurations.
- LLM Synthesis: LLMs (specifically GPT-4o-mini) are used to fill in the
nanobinddefinitions for individual classes.

Overcoming the "Hallucination" Gap
The study identifies critical failure modes where LLMs struggle with C++:
- Shared Pointers: LLMs frequently try to use
pybind11syntax (holders) instead ofnanobind's header-based approach. - Trampolines: To allow Python to override C++ virtual functions, a "trampoline" class is required. LLMs failed this 100% of the time without In-Context Examples.
- Overload Resolution: Models often skip the necessary
nb::overload_castneeded to disambiguate C++ functions.
Technical Deep-Dive: Core Binding Patterns
The paper categorizes robotics bindings into three essential patterns:
- Direct Bindings: Simple mapping of POD (Plain Old Data) classes.
- Callback Bindings: Allowing C++ to call Python routines (crucial for custom collision checkers).
- Polymorphic Bindings: Allowing Python classes to inherit from C++ base classes (enabling custom planners in Python).
Figure: A concrete example of using nanobind to expose C++ class members and constructors to Python.
Experiments: Performance Without Compromise
The authors benchmarked the new nanobind interface against the old Boost.Python version across several tasks, including PyBullet integration and constrained planning.
| Experiment | nanobind (ms) | Boost.Python (ms) |
|---|---|---|
| KPIECE Planning | 2346.3 | 3324.5 |
| RRT-Connect (2D) | 4.4 | 4.5 |
| Sample in PyBullet | 16.5 | 17.5 |
The results show that nanobind is consistently faster or equal to the legacy solution, particularly in complex control-based planning where the overhead of cross-language calls (trampolines and callbacks) is most significant.
Critical Insight & Conclusion
The true value of this paper isn't just a "faster OMPL." It provides a blueprint for modernizing legacy codebases.
Key Takeaways:
- Don't trust the AI blindly: LLMs are excellent at
nanobindboilerplate but terrible at C++ memory management (shared_ptr) and template logic. - In-context learning is king: Providing one solid, manually-written "template" file for a trampoline improved LLM success rates from 0% to 100%.
- Maintainability: By fracturing the bindings into modular files that mirror the C++ source, the authors made it easier for future contributors (and future LLMs) to update the code.
This study serves as a successful case study in "Cybernetic Software Engineering"—using AI to eliminate the "tedious" parts of systems programming while retaining high-level human architectural control.
