Skip to main content

pydantic-ai-gedanken

Experimental capabilities for Pydantic AI agents.

DynamicOutput

DynamicOutput is an agent capability that removes the need to fix an output type up front: the agent authors its own output type at runtime as a JSON Schema, which is converted into a real Pydantic model that evolves gradually across versions.

How it works:

  1. Author — the agent calls author_output_schema(name, json_schema). The draft schema is lint-checked, converted into a Pydantic model by datamodel-code-generator, and the generated Python source is handed back to the agent so it authors against real code, not raw JSON.
  2. Activate — the generated model immediately becomes the agent's output type for its final answer. Companion tools list_output_schemas and deactivate_output_schema manage the lifecycle.
  3. Verify — after the run completes, user-supplied Verifier checks run against the active model. If any fail, the agent is re-run with the failure messages so it can evolve the schema, up to max_retries times.
  4. Persist — every version is stored on disk as a plain Python module (<name>.v<version>.py) indexed by a manifest.json with statuses (draft/active/inactive), timestamps, and last errors. Modules can be read and hand-edited; edits are picked up on the next run.

Usage

from pathlib import Path

from pydantic import BaseModel
from pydantic_ai import Agent

from pydantic_ai_gedanken.capabilities.dynamic_output import (
    DynamicOutput,
    VerificationResult,
    Verifier,
)


async def requires_name(model: type[BaseModel]) -> VerificationResult:
    ok = 'name' in model.model_fields
    return VerificationResult(passed=ok, message='ok' if ok else "declare a 'name' field")


dynamic_output = DynamicOutput(
    directory=Path('.output_models'),
    verifiers=[Verifier(name='requires_name', check_fn=requires_name)],
)
agent = Agent(
    'anthropic:claude-sonnet-4-6',
    capabilities=[dynamic_output],
    output_type=[str, DynamicOutput.placeholder_output_type()],
)

To let the run end with the evolved output type, construct the agent with DynamicOutput.placeholder_output_type() — its output tool definition is rewritten in place with the active model's schema. To reuse the evolved model in another agent, thread dynamic_output.store.active_output_type() into it.

Development

Requires uv.

make install    # install package + dev deps and set up pre-commit hooks
make format     # auto-format and fix with ruff
make lint       # check formatting and lint
make typecheck  # run pyright
make test       # run pytest
make            # run all of the above

Metadata

Release files for pydantic-ai-gedanken 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydantic-ai-gedanken 0.1.0
File Size Uploaded Provenance Actions
pydantic_ai_gedanken-0.1.0.tar.gz 189.2 kB With provenance Details for pydantic_ai_gedanken-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydantic-ai-gedanken 0.1.0
File Interpreter ABI Platform Actions
pydantic_ai_gedanken-0.1.0-py3-none-any.whl Python 3 none any Details for pydantic_ai_gedanken-0.1.0-py3-none-any.whl

Total release size: 208.9 kB

Release files / pydantic_ai_gedanken-0.1.0.tar.gz

Download URL pydantic_ai_gedanken-0.1.0.tar.gz
Size 189.2 kB
Tags Source
SHA-256 checksum
How to use checksums
c57837eef5ac86517365b9f778c194caa9387257009a3fa2968a4f50702f919c
BLAKE2b-256 checksum
How to use checksums
87bd16f4c586420ab6b7836a829010feef9ab1c83545c77d4aad13c53b800eee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Release files / pydantic_ai_gedanken-0.1.0-py3-none-any.whl

Download URL pydantic_ai_gedanken-0.1.0-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8f4763ca5ba556f01057460aaaedba8faa37dbc94ec0ea509f011ee130857a2
BLAKE2b-256 checksum
How to use checksums
c8ce1a3f3e4b25c01ad30dca5ff4d3a98e157dce026287ba14f4e3184884839f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

Security for pydantic-ai-gedanken 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pydantic_ai_gedanken-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 30, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page