Skip to main content

This package has moved. djangorestframework-pydantic-ai is no longer developed; 0.36.x is its final line, and 0.36.3 only fixes the test doubles in rest_framework_pydantic_ai.testing for pydantic-ai 2.60 and later. Development continues as django-spec-agents, where this package is now django_spec_agents.spec_tools (pip install "django-spec-agents[specs]"). See Moving to django-spec-agents for what each name became, and the new documentation.

djangorestframework-pydantic-ai

CI PyPI Python versions Django versions Docs Coverage Ruff License

Expose djangorestframework-services services and selectors as a Pydantic-AI toolset, so a plain pydantic_ai.Agent can call them as tools — no MCP server and no AG-UI bridge in the path.

Every tool call routes through drf-services' transport-neutral surface (dispatch_spec plus its off-HTTP helpers), so a tool call runs the same input validation, the same permission_classes — both class-level has_permission and object-level has_object_permission on the resolved row — and the same serializer rendering your DRF views apply, just without the HTTP hop.

Install

pip install djangorestframework-pydantic-ai

It depends only on djangorestframework-services and pydantic-ai-slim. A model provider is pulled in separately, the usual Pydantic-AI way (e.g. pip install "pydantic-ai-slim[anthropic]").

Quickstart

from pydantic_ai import Agent
from rest_framework_pydantic_ai import AgentDeps, SpecToolset

toolset = SpecToolset(
    {
        "list_orders": orders_selector_spec,  # SelectorSpec -> read-only tool
        "create_order": create_order_spec,  # ServiceSpec  -> mutation tool
    }
)

agent = Agent("anthropic:claude-opus-4-8", deps_type=AgentDeps, toolsets=[toolset])

result = await agent.run(
    "create an order of 3 widgets",
    deps=AgentDeps(user=request.user),
)

The agent acts as deps.user: each call builds an off-HTTP request/view context, enforces the spec's permission_classes (class- and object-level), dispatches the spec, and renders the result through the spec's serializer. List selectors gain page / limit / order tool args, and return one page — {"items": [...], "page": 1, "totalPages": N, "hasNext": bool} — so a model reading a collection can tell whether it saw all of it.

Failures map onto the model loop so the agent self-corrects: invalid input, a bad page / limit / order value, and unexpected (hallucinated) arguments come back as ModelRetry; a business error or missing row becomes a readable ToolFailed, which the model sees as a failed call rather than a successful one carrying prose, and a call an Affordance refuses names the rule as well as the reason (The books are closed. (code: books_closed)); a denied permission raises PermissionDenied, which aborts the run under a plain pydantic_ai.Agent. A host that installs a tool-failure policy — django-pydantic-agent's build_agent does by default — turns that denial into a failed-tool result instead, so the run continues; the call is still denied either way. Unexpected arguments are rejected by default — pass unknown_arguments=UnknownArguments.IGNORE to SpecToolset to drop them instead.

A tool whose Affordance condition is unmet right now, such as posting to a closed period, is left out of that step's tool list, and the step's instructions name it with its reason so the model can tell the user why. Permissions do not filter the list: a denied tool is still offered, and the denial comes on the call.

Every line of the instructions block is a field of AgentConventions, the heading of the unavailable list included, and so are a handle field's fallback description, the sentence scoping a paged tool's read-shaping parameters, and the missing-argument retry. SpecToolset(specs, conventions=AgentConventions(pagination=...)) rewords one line and leaves the rest as they are. The toolset still decides when each line is said, and None drops a line. Argument descriptions, such as those of limit and page, and the toolset's other retries stay fixed.

An argument the model must not choose, such as the project a run is scoped to, is the server's to supply: SpecToolset(registry, tool_server_arguments={"list_vendors": ServerArguments(values={"project_pk": "7"})}) binds it on every call to that tool, takes it out of the tool's schema, and drops whatever the model sends under it. ServerArguments.withheld keeps a name from the model with no value in its place, so its default answers.

See the documentation for the full reference.

License

MIT

Metadata

Release files for djangorestframework-pydantic-ai 0.36.3

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

Source distribution (sdist)

Source distribution for djangorestframework-pydantic-ai 0.36.3
File Size Uploaded Provenance Actions
djangorestframework_pydantic_ai-0.36.3.tar.gz 373.1 kB With provenance Details for djangorestframework_pydantic_ai-0.36.3.tar.gz

Built distribution (wheel)

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

Total release size: 457.2 kB

Release files / djangorestframework_pydantic_ai-0.36.3.tar.gz

Download URL djangorestframework_pydantic_ai-0.36.3.tar.gz
Size 373.1 kB
Tags Source
SHA-256 checksum
How to use checksums
220b8a02ee98d296799f97155bd1e2227d41560d1f8543779b982e078f1e805e
BLAKE2b-256 checksum
How to use checksums
c9d46702e6291d97560ddf0ff8608e24589d2eaab7b73b8b5b2927a37af0564d
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 Oct 26, 2026.

Transparency log

Release files / djangorestframework_pydantic_ai-0.36.3-py3-none-any.whl

Download URL djangorestframework_pydantic_ai-0.36.3-py3-none-any.whl
Size 84.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f24aeceb4a0a4e197f7e7d48031eabcbda7b1508c1ae884f71a66aeed76f2609
BLAKE2b-256 checksum
How to use checksums
9884dcdbdaccb71a311243dced3c68e4862f47b3f5e3e0261853277535bffc0e
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 Oct 26, 2026.

Transparency log

Security for djangorestframework-pydantic-ai 0.36.3

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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for djangorestframework_pydantic_ai-0.36.3.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 Oct 26, 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.36.3 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