https://github.com/lukaflpvc/dynamic-pydantic
create pydantic models dynamically
https://github.com/lukaflpvc/dynamic-pydantic
agentic-ai instructor llm pydantic-v2 validation
Last synced: 2 months ago
JSON representation
create pydantic models dynamically
- Host: GitHub
- URL: https://github.com/lukaflpvc/dynamic-pydantic
- Owner: lukaflpvc
- License: mit
- Created: 2024-12-20T03:41:50.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-02-01T00:35:41.000Z (11 months ago)
- Last Synced: 2025-09-30T15:19:18.887Z (3 months ago)
- Topics: agentic-ai, instructor, llm, pydantic-v2, validation
- Language: Python
- Homepage:
- Size: 109 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Dynamic Pydantic
**Dynamic Pydantic is the easiest way for AI agents to create and validate tools and databases in runtime.**
It is a provides a powerful approach to creating pydantic models dynamically for any given task.
The project leverages Instructor and Pydantic to generate models dynamically based on provided prompt and context.
## Installation
```bash
uv pip install dynamic-pydantic
```
## Contributing
Start contributing by cloning the repository:
```bash
git clone https://github.com/lukafilipxvic/dynamic-pydantic.git
```
## Usage
This package simplifies the interaction between language models and pydantic's ```create_model()``` function.
Below is a basic example showcasing the generation of a Pydantic schema with Cerebras' Llama 3.3 70b inference.
Dynamic Pydantic works with any OpenAI-compatible endpoint via LiteLLM.
```
from dynamic_pydantic import dynamic_model
genModel = dynamic_model(prompt='User = Name, Age')
print(f'{genModel.schema_json()}')
# {"properties": {"Name": {"default": null, "description": "The user's name", "title": "Name", "type": "string"}, "Age": {"default": null, "description": "The user's age", "title": "Age", "type": "integer"}}, "title": "User", "type": "object"}
```
## License
This project is licensed under the terms of the MIT license.
For more details, refer to the LICENSE file in the repository.