How does Pydantic AI reduce hallucinations in AI agents?

Short answer: Anand Chandrasekaran says Pydantic AI's dependencies let typed inputs steer an agent's thinking, so 90 to 95% of everyday agent tasks need no examples, and his hallucinations dropped 40 to 50% after moving off JSON types.

Watch this answer from Episode 24

Watch this answer from Episode 24 (starts at 18:08) · Episode 24 notes and transcript

What was said on Built This Week

From Episode 24: This AI Fills Healthcare Shifts in Minutes, starting at 18:08.

Anand Chandrasekaran [18:07]: I think one useful tip that I would like to give to people, one of the things that I solved for our use case, it became very evident when I started experimenting with something called Pydantic AI. Pydantic is the base model in Python that's that's what was being used by Anthropic and other agents internally for their LLMs. So with Pydantic AI, when you use that, you get something called as dependencies, which is like an input type. And when you use that, almost 90 to 95% of the things that we do in our normal day to day AI agents, we don't have to give examples. You can control that using input type. And I use that quite a lot for flags, for doing things that kind of you know, it's like the best word to use is to navigate the agent's thinking in one particular way by using the control structure that it understands. After using yeah. After starting to use that, it's been extremely fast development and the hallucinations have reduced 40 to 50% for me just by changing the input types with Pydantic AI. So if you're building single agents, single short agents, I really highly recommend people using Pydantic AI for So

Jordan Metzner [19:21]: That's oh, wow. So okay. So that's like the progression from moving from like JSON type or like any type of like, formatted type prompts, I guess.

Anand Chandrasekaran [19:29]: Owned into all Pydantic classes. No more JSON types. So yeah.

Jordan Metzner [19:34]: Okay. Alright. Awesome. I'm like, I'm gonna do this next, like, after this call. After our show ends, I'm going straight to download the library and create some outputs.

More questions from this episode

Go deeper

New episode every week

Watch us build with AI, live.

Real builds, founder interviews and the AI news that matters. Join 43K+ builders on YouTube.

▶ Subscribe on YouTubeBrowse all episodes →