Skip to main content

runtype-pydantic-ai

Send Pydantic AI agent runs to Runtype. Each run appears as a first-class execution: transcript, system prompt, model calls, tool calls with arguments and results, token usage, cache usage, cost, loop iterations, stop reason and sub-agents.

  • Works with pydantic-ai 1.90+ and 2.x from one entry point.
  • Composes with Logfire and any OpenTelemetry setup. Your other exporters keep receiving the original spans, and only agent-run spans reach Runtype.
  • Sends everything Runtype can show by default. Every content kind has its own off switch, and content=False sends shape and cost only. Exception messages and stack traces never leave the process; a failed run reports the exception class name.

Install

pip install runtype-pydantic-ai

Quick start

Set RUNTYPE_API_KEY to a key with the TELEMETRY:WRITE scope and RUNTYPE_AGENT_ID to the Runtype agent that owns the runs. Then add one call at startup:

import runtype_pydantic_ai

runtype_pydantic_ai.instrument()

Every Agent in the process is now traced. Spans are exported in batches, so a run reaches Runtype a few seconds after it ends. In a short-lived script or a test that checks the export, keep the handle and flush before exit or before asserting:

handle = runtype_pydantic_ai.instrument()
...
handle.force_flush()

With Logfire

Call instrument() after logfire.configure() and it joins Logfire's provider. Alternatively, pass the processor in:

import logfire
import runtype_pydantic_ai

logfire.configure(additional_span_processors=[runtype_pydantic_ai.span_processor()])
logfire.instrument_pydantic_ai(include_content=True, version=5)

Any instrumentation format from 2 up works, so keep the one your Logfire queries read. Format 2 uses the older span names (agent run, running tool), and Runtype receives the same attributes from it as from format 5. instrument() itself sets format 5.

With another OpenTelemetry provider

instrument() leaves a global non-Logfire provider alone and traces through a private one, because prompt content would otherwise reach every exporter on it. To share a provider, pass it:

runtype_pydantic_ai.instrument(tracer_provider=provider)

Its other exporters then receive raw content, and redact does not apply to them. Use content=False to keep content off every exporter.

If Agent.instrument_all() already ran, instrument() keeps those settings and joins the provider they use, and raises if it cannot reach that provider. An agent with its own instrumentation, such as Agent(instrument=True), traces to its own provider, so pass that provider too.

Several agents in one process

Map Pydantic AI agent names to Runtype agents, or pin a block of code to one:

runtype_pydantic_ai.instrument(agent_ids={"chat": "agent_a", "run": "agent_b"})

with runtype_pydantic_ai.runtype_agent("agent_c"):
    await agent.run("...")

A sub-agent called from a tool stays a branch of the outer run, under the outer run's Runtype agent.

Every top-level run is its own Runtype execution, even when several share a web request's span. A run under such a span gets a new trace id in Runtype, so it will not match the id in your other backend.

One agent only

To trace a single agent rather than all of them:

handle = runtype_pydantic_ai.instrument()
Agent.instrument_all(False)
agent = Agent("openai:gpt-5-mini", capabilities=[runtype_pydantic_ai.capability(handle)])

Early 1.x releases have no public Instrumentation capability, and capability() says so. Use Agent(instrument=handle.settings) there.

Content

By default Runtype receives prompts, instructions, model output and tool arguments and results as written. Any personal data your prompts carry, such as a user's record placed in the first message, reaches Runtype too. Turn it off or scrub it here:

from runtype_pydantic_ai import ContentOptions

runtype_pydantic_ai.instrument(content=False)
runtype_pydantic_ai.instrument(content=ContentOptions(tool_results=False, max_chars=16_384))
runtype_pydantic_ai.instrument(content=ContentOptions(redact=lambda value, attribute: scrub(value)))

Each switch also applies inside message lists. tool_arguments=False and tool_results=False remove those payloads from tool call parts, system_instructions=False removes system messages, and output_messages=False removes earlier assistant turns from gen_ai.input.messages.

redact receives the parsed value and the attribute name. Returning None, or raising, drops that one attribute and keeps the span.

Values are capped to fit ingest's limits. Oversized message lists stay valid JSON: large parts become a marker, then the oldest turns are dropped and the newest kept.

Custom attributes

Attributes are allow-listed. To send your own, name their prefixes:

runtype_pydantic_ai.instrument(passthrough_attribute_prefixes=["myapp."])

Options

Environment variable Purpose
RUNTYPE_API_KEY Runtype key with the TELEMETRY:WRITE scope. Required.
RUNTYPE_AGENT_ID Default Runtype agent for runs.
RUNTYPE_OTLP_URL Full trace URL. Defaults to https://api.runtype.com/v1/otel/v1/traces.

Metadata

Release files for runtype-pydantic-ai 0.2.1

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

Source distribution (sdist)

Source distribution for runtype-pydantic-ai 0.2.1
File Size Uploaded Provenance Actions
runtype_pydantic_ai-0.2.1.tar.gz 23.6 kB Without provenance Details for runtype_pydantic_ai-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 41.9 kB

Release files / runtype_pydantic_ai-0.2.1.tar.gz

Download URL runtype_pydantic_ai-0.2.1.tar.gz
Size 23.6 kB
Tags Source
SHA-256 checksum
How to use checksums
78b157e5c73d6a129a37ff259bc7252b47ff4418ec5b39ce9330f628d0f5a107
BLAKE2b-256 checksum
How to use checksums
ccf2275c643351bc2a1ae5f1bbb31eaf438fb21aa8059617b978ebbc1f779d52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / runtype_pydantic_ai-0.2.1-py3-none-any.whl

Download URL runtype_pydantic_ai-0.2.1-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4748b27ab0fd5b7367c09b01a646c7059efa0a8e5c276ea25f004a58577c9b4
BLAKE2b-256 checksum
How to use checksums
70566cfc468f620e3667e3eb6801d957724ddc40f8e44d6cb2bf5afe7d125099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.12.13

Security for runtype-pydantic-ai 0.2.1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.2.1 This release

2 release files No 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