new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Pydantic · all subjects

logfire

12 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Logfire Pydantic integration overview

Logfire's Pydantic integration records each validation as it runs, capturing the input alongside any validation errors. This makes troubleshooting validation errors in production easier by recording failed validations as they happen, so you can examine the specific failure instead of reconstructing it from logs after the fact.

logfire.instrument_pydantic() usage

Call logfire.instrument_pydantic() to set up Pydantic instrumentation. The record parameter controls what gets traced: record='failure' (recommended) records a trace for each failed validation while still collecting metrics for all validations, and record='all' (the default) records a trace for every validation including successful ones.

What Logfire captures for failed validations

When a validation fails, Logfire records: the exact input data passed to validation, the surrounding context as a span within the request or trace showing where bad data originated, the queryable error history for analysis, and automatic error tracking without requiring additional logging code.

Sensitive data scrubbing in Logfire

The Logfire SDK automatically scrubs common sensitive values like passwords, tokens, and other secrets from spans before they leave your machine. You can extend these scrubbing rules for your own custom fields.

Structured errors in Logfire traces

Failed validation spans in Logfire show the raw structured errors() list from pydantic_core.ValidationError alongside the input that produced it. Each error includes the field path (loc), the machine-readable type, and the offending value, allowing you to see which field failed and with what value without parsing the rendered message string.

Logfire groups repeated validation failures into issues

Logfire automatically groups repeated validation exceptions into issues, so a validation that fails many times shows up as one entry with a count and a first-seen time, rather than many individual log lines. This makes it easy to distinguish genuine spikes from background noise.

Logfire alerts for validation failures

Logfire supports alerts that run SQL queries on a schedule to notify you (for example in Slack) when specified conditions are met. You can set up rules like 'validation failures for this model crossed a threshold' to be proactively notified of recurring validation issues.

Logfire error explanation feature

Logfire has a beta feature that explains validation failures in plain language by reading the structured errors and telling you what was expected and what was received for each field, including messages from custom validators. This allows you to understand failures without memorizing error codes.

Logfire MCP server for AI debugging

The Logfire MCP server allows AI coding agents to query your telemetry directly, including the input and errors from a failed validation, so the agent can investigate against your real data instead of guessing.

Example: Basic Logfire instrumentation

from datetime import date import logfire from pydantic import BaseModel logfire.configure() logfire.instrument_pydantic(record='failure') class User(BaseModel): name: str country_code: str dob: date User(name='Anne', country_code='USA', dob='not-a-date') This example configures Logfire to record failed validations and defines a User model. Passing an invalid date value triggers a validation error that Logfire records with the input, error, and surrounding context.

Logfire integration for Pydantic AI debugging

Pydantic AI runs can be instrumented with Logfire to record validation errors, retries, and the full lifecycle of agent execution. Logfire records the output the model produced, the errors your validators raised, and the retry that followed.

Logfire integration uses validation plugin hook

Logfire, an observability tool, uses the plugin hook mechanism to record validations without any per-call instrumentation.

Give your agent this brain