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 · Integrations · all subjects

datamodel-code-generator

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

datamodel-code-generator: data sources supported

datamodel-code-generator can generate Pydantic models from OpenAPI 3 (YAML/JSON), JSON Schema, JSON/YAML/CSV Data (converted to JSON Schema), Python dictionary (converted to JSON Schema), and GraphQL schema.

datamodel-code-generator installation

Install datamodel-code-generator using: pip install datamodel-code-generator

datamodel-code-generator: basic command syntax

The basic command to generate Pydantic models is: datamodel-codegen --input <filename> --input-file-type <type> --output <output_file>. For example: datamodel-codegen --input person.json --input-file-type jsonschema --output model.py

datamodel-code-generator: JSON Schema to Pydantic models example

This example generates Pydantic models from a JSON Schema file. The generated model.py contains: ```python from __future__ import annotations from typing import Any from pydantic import BaseModel, Field, conint class Pet(BaseModel): name: str | None = None age: int | None = None class Person(BaseModel): first_name: str = Field(description="The person's first name.") last_name: str = Field(description="The person's last name.") age: conint(ge=0) | None = Field(None, description='Age in years.') pets: list[Pet] | None = None comment: Any | None = None ``` This shows how JSON Schema properties map to Pydantic Field definitions, constraints like minimum become conint(ge=0), descriptions are preserved, and required fields are determined from the schema's required array.

datamodel-code-generator: schema drift detection

A model generated from an OpenAPI or JSON Schema document is a snapshot of that contract. When upstream data stops matching the generated model (a field changes type, a new required field appears), the mismatch surfaces as a ValidationError at runtime. This is often the first sign the source has drifted from the schema.

datamodel-code-generator: schema drift monitoring with Logfire

When recording validations with Logfire, validation failures are stored with the payload that caused them. This allows you to see what changed and when it started, which is useful when you don't own the schema and can't regenerate the models until you know what moved.

Give your agent this brain