When working with Pydantic models, it's straightforward to emit fully nested JSON structures. However, transitioning to SQLModel for integration with tools like CrewAI or LlamaIndex can complicate the ability to easily output nested JSON schemas or model data. This poky little guide provides a detailed explanation of how I adapted our models to preserve nested JSON structures after migrating to SQLModel. Below, we present a simple before-and-after example showcasing the necessary changes.
To achieve a consistent and functional setup using SQLModel and Pydantic, several key changes were implemented across different model definitions. These adjustments ensured the seamless integration of nested data structures and improved data handling.