r/pydantic • • Sep 04 '24

Need a discriminator at runtime…

1 Upvotes

Hi, I have a model that contains a dict of sub models. However the values of the dict are heterogeneous. I can’t simply create a discriminated union because I don’t know what models will be in the union until it’s running.

It seems like I should be able to do this with a root model and a type adapter, but it’s not clear how. Do I need a custom validator on my root model to call validate_Python from? Or can I just reference the type adapter directly from the signature of the root model somehow?

If I need a validator also, which one?


r/pydantic • • Aug 14 '26

5 open-source repos that do the loop-and-graph engineering, so you stop hand-rolling parallel agents.

Post image
4 Upvotes

r/pydantic • • Aug 06 '26

Turn your Pydantic AI + Logfire traces into an interactive workflow diagram (open source)

2 Upvotes

r/pydantic • • Aug 06 '26

Opinionated docs

Post image
2 Upvotes

r/pydantic • • Aug 12 '26

Hack Monty Round 3: a $20,000 bounty to escape a Rust-based Python sandbox

3 Upvotes

Monty is an open-source, minimal Python interpreter written in Rust (github.com/pydantic/monty). Startup is measured in microseconds, and it inverts the usual sandbox model: it starts from nothing and only exposes the functions you explicitly hand it.

We're running a $20,000 bounty (with Prefect and Hugging Face Face) for anyone who can escape the sandbox and read a secret off the server running it.

What changed since the last round: Monty now runs in a subprocess behind a WebSocket service over a protobuf wire protocol, so old REST-era approaches don't carry over. There's also a new mount feature that lets Monty read a directory on the client machine, and a separate bounty for escaping it.

Nobody escaped the last round. Round 1 fell to a use-after-free in under 48 hours.

This is (probably) the last round before we tag Monty V1, so it's your last crack at the interpreter as it stands.

Full rules: https://pydantic.dev/monty

Happy to talk about the interpreter internals or the sandbox model in the comments.


r/pydantic • • Aug 06 '26

Let's revive this dormant subreddit

4 Upvotes

this place has has been quiet for a while, let's fix that. I work on Pydantic and I'm going to start posting here regularly: tips, new features, things I see people get wrong, community questions.

What would you like to see here?


r/pydantic • • Oct 08 '26

pcode: an open-source terminal coding agent built on Pydantic AI

4 Upvotes

I built pcode, an MIT-licensed terminal coding agent built on Pydantic AI. Sharing it here as a Pydantic AI ecosystem project, rather than a data-validation library.

Its extension interface uses Pydantic AI capabilities: Python files can add tools, slash commands, guardrails and sub-agents. The application builds on Pydantic AI's Harness coder and adds terminal interaction, saved conversations, browser automation with your existing logins, background jobs and worktree-based sessions.

One UI detail is native terminal scrollback whose detail level can change after a turn finishes. Commands, output and diffs can be shown or hidden without rerunning anything; ordinary terminal scrolling, search and copy still work. You can also rewind and branch conversations, customize keybindings or use Vim editing, and inspect changes in a diff popup.

Long-running commands can continue as background jobs and wake the agent on completion. Separate git worktrees support parallel sessions. It works with existing Claude/ChatGPT subscriptions or API keys; model access is separate from the open-source application. It edits files and runs shell commands with your permissions and no approval prompt, so read the tool-permissions documentation first.

Code, screenshots and documentation: https://github.com/cruxwell/pcode


r/pydantic • • Aug 20 '26

Trying to create a list subclass containing only certain classs that is validated by Pydantic BaseModel

2 Upvotes

I am trying to create list subclasses that only take particular classes. These lists can be appended to and the like but each time the list is changed the item is checked to see whether it is the same class as the rest of the list.

The list methods that are overwritten are:
- __init__
- __set_item__
- __str__
- append
- extend
- insert

Each one runs through a validate_member method before changing the list.

As an example, I want to make a list subclass called Course that only takes Pydantic extra types Coordinate values. I want this list subclass to be a valid BaseModel attribute.

Right now I’m having to use a field_validator for every class that Course and the other lists are in which feels redundant, unpythonic, and is a pain to have to do every time. I am having to do so because it says something about arbitrary types.

I was wondering if someone might have some advice.


r/pydantic • • 26d ago

Pydantic AI seems to be everywhere

Thumbnail
reddit.com
2 Upvotes

r/pydantic • • Aug 31 '26

👋 Welcome to r/pydantic - Introduce Yourself and Read First!

3 Upvotes

Hey everyone! I'm u/louisbsc, a moderator of r/pydantic.

This is our new home for all things related to Pydantic data validation, Pydantic AI, Pydantic Logfire, and HTTPX2. We're excited to have you join us!

What to Post
Post anything that you think the community would find interesting, helpful, or inspiring. Feel free to share your thoughts, photos, or questions about AI, agents, BaseModels, capabilities, observability, tracing, or anything else you think could be useful.

Community Vibe
We're all about being friendly, constructive, and inclusive. Let's build a space where everyone feels comfortable sharing and connecting.

How to Get Started

  1. Introduce yourself in the comments below.

  2. Post something today! Even a simple question can spark a great conversation.

  3. If you know someone who would love this community, invite them to join.

Thanks for being part of the very first wave. Together, let's make r/pydantic amazing.


r/pydantic • • 22d ago

Pydantic V3 is coming soon

2 Upvotes

Pydantic validation V3 is in the works. A lot of people went through the V1 to V2 migration, and we know it wasn’t easy. The team is working to make sure this one is much less painful.

So here’s a commitment: every breaking change in V3 will be one of the following

  • a correctness fix, such as a bug that affects a minority of users

  • a change where you can easily opt back in to the previous behaviour

If you’re using Pydantic in production and would rather talk to a Pydantic engineer to plan the migration, we’re also launching Enterprise support for exactly that.

Blogpost with the full story: https://pydantic.dev/articles/pydantic-validation-next-steps

Happy to answer questions in the comments.