drf-tool-schema
Generate function-calling tool schemas from Django REST Framework serializers. Compatible with any LLM provider that follows the OpenAI tool calling standard — including OpenAI, Anthropic Claude, OpenRouter, Groq, Mistral, and LiteLLM.
Instead of writing tool schemas by hand and keeping them in sync with your serializers manually, drf-tool-schema introspects the serializer and builds the schema automatically. Change a field in your serializer and the tool schema updates with it.
Installation
pip install drf-tool-schema
Usage
from drf_tool_schema import schema_from_serializer
from partners.serializers import PartnerWriteSerializer
SCHEMAS = [
schema_from_serializer(
name="create_customer",
description="Creates a new customer in the system. Returns the created customer ID.",
serializer=PartnerWriteSerializer(),
required_override=["legal_name", "tax_id"],
),
]
This produces:
{
"type": "function",
"function": {
"name": "create_customer",
"description": "Creates a new customer in the system. Returns the created customer ID.",
"parameters": {
"type": "object",
"properties": {
"legal_name": { "type": "string", "description": "Official registered company name." },
"tax_id": { "type": "string", "description": "NIF / CIF / VAT number." },
"country": { "type": "string", "description": "ISO 3166-1 alpha-2 country code.", "default": "ES" }
},
"required": ["legal_name", "tax_id"]
}
}
}
Pass the schema directly to your LLM client:
# OpenAI
client.chat.completions.create(model="gpt-4o", messages=[...], tools=SCHEMAS)
# Anthropic Claude
client.messages.create(model="claude-sonnet-4-20250514", messages=[...], tools=SCHEMAS)
# OpenRouter / Groq / Mistral / any OpenAI-compatible provider
client.chat.completions.create(model="...", messages=[...], tools=SCHEMAS)
Parameters
| Parameter | Type | Description |
|---|---|---|
name |
str |
Tool name in snake_case |
description |
str |
Description sent to the LLM |
serializer |
Serializer |
Instantiated DRF serializer |
required_override |
list[str] | None |
Override required fields. If None, uses serializer's required flags |
exclude |
list[str] | None |
Field names to exclude (read-only fields are always excluded) |
Field type mapping
| DRF field | JSON Schema type |
|---|---|
CharField, EmailField, URLField, DateField, DateTimeField, UUIDField |
string |
IntegerField |
integer (with minimum / maximum if set) |
DecimalField, FloatField |
number |
BooleanField |
boolean |
ChoiceField |
string + enum |
ListField |
array |
Nested Serializer |
object (inlined) |
Fields with read_only=True are always excluded.
Field descriptions come from help_text, falling back to label.
Development
pip install -e ".[dev]"
pytest
# or without pytest:
python tests/test_builder.py
License
MIT
Metadata
Release files for drf-tool-schema 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drf_tool_schema-0.1.0.tar.gz | 7.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drf_tool_schema-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.0 kB
Release files / drf_tool_schema-0.1.0.tar.gz
| Download URL | drf_tool_schema-0.1.0.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
48c4748986de5610c83c6c4e831848e89e1da6a98a969baadee941e0ca7b44c3
|
|
BLAKE2b-256 checksum How to use checksums |
2fbe790ac8e76034d315ea7b65bbf42f10b373373e78362bd75e61eee9f164b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 19, 2026.
Transparency logRelease files / drf_tool_schema-0.1.0-py3-none-any.whl
| Download URL | drf_tool_schema-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5f1a0f630c6330525857d30693638bd7e2eaa897483534fc139088dcc80ce9cb
|
|
BLAKE2b-256 checksum How to use checksums |
eba62f40195c10efe5a6e9207321df283c69a1418e42bb4ed74cde76c1116578
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 May 19, 2026.
Transparency log