Skip to content

Introduction

Welcome to Modelsmith

Modelsmith is a Python library that allows you to get structured responses in the form of Pydantic models and Python types from Google Vertex AI and OpenAI models.

Currently it allows you to use the following classes of model:

  • AnthropicModel (used with Anthropic's full set of models)

  • OpenAIModel (used with OpenAI's full set of models)

  • GeminiModel (used with Google's full set of Gemini models)

Modelsmith provides a unified interface over all of these. It has been designed to be extensible and can adapt to other models in the future.

Notable Features

Structured Responses: Specify both Pydantic models and Python types as the outputs of your LLM responses.

Templating: Use Jinja2 templating in your prompts to allow complex prompt logic.

Default and Custom Prompts: A default prompt template is provided but you can also specify your own.

Retry Logic: Number of retries is user configurable.

Validation: Outputs from the LLM are validated against your requested response model. Errors are fed back to the LLM to try and correct any validation failures.