Generate function-calling tool schemas from DRF serializers. Compatible with OpenAI, Anthropic Claude, OpenRouter, Groq, Mistral, and any OpenAI-compatible LLM provider.
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file drf_tool_schema-0.1.0.tar.gz.
File metadata
- Download URL: drf_tool_schema-0.1.0.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48c4748986de5610c83c6c4e831848e89e1da6a98a969baadee941e0ca7b44c3
|
|
| MD5 |
4dc99fd91a271b8702b959e55f2bc11e
|
|
| BLAKE2b-256 |
2fbe790ac8e76034d315ea7b65bbf42f10b373373e78362bd75e61eee9f164b7
|
Provenance
The following attestation bundles were made for drf_tool_schema-0.1.0.tar.gz:
Publisher:
publish.yml on SebassContreras/drf-tool-schema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_tool_schema-0.1.0.tar.gz -
Subject digest:
48c4748986de5610c83c6c4e831848e89e1da6a98a969baadee941e0ca7b44c3 - Sigstore transparency entry: 1573452573
- Sigstore integration time:
-
Permalink:
SebassContreras/drf-tool-schema@8b1beb95b922882364260936760694289c0fef13 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/SebassContreras
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b1beb95b922882364260936760694289c0fef13 -
Trigger Event:
push
-
Statement type:
File details
Details for the file drf_tool_schema-0.1.0-py3-none-any.whl.
File metadata
- Download URL: drf_tool_schema-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f1a0f630c6330525857d30693638bd7e2eaa897483534fc139088dcc80ce9cb
|
|
| MD5 |
ea068ee511100edba1f229e991cc7a8f
|
|
| BLAKE2b-256 |
eba62f40195c10efe5a6e9207321df283c69a1418e42bb4ed74cde76c1116578
|
Provenance
The following attestation bundles were made for drf_tool_schema-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on SebassContreras/drf-tool-schema
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_tool_schema-0.1.0-py3-none-any.whl -
Subject digest:
5f1a0f630c6330525857d30693638bd7e2eaa897483534fc139088dcc80ce9cb - Sigstore transparency entry: 1573452622
- Sigstore integration time:
-
Permalink:
SebassContreras/drf-tool-schema@8b1beb95b922882364260936760694289c0fef13 -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/SebassContreras
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8b1beb95b922882364260936760694289c0fef13 -
Trigger Event:
push
-
Statement type: