Skip to main content

Validate LLM tool-call payloads with small JSON-like contracts. Python port of @mukundakatta/tool-call-contracts.

Project description

tool-call-contracts-py

Validate LLM tool-call payloads with small JSON-like contracts. Pure Python, zero deps. Python port of @mukundakatta/tool-call-contracts.

pip install tool-call-contracts-py
from tool_call_contracts import validate_tool_call, assert_tool_call, ContractError

contract = {
    "name": "search",
    "arguments": {
        "query": {"type": "string", "required": True},
        "limit": {"type": "int", "enum": [10, 25, 50]},
    },
}

res = validate_tool_call({"name": "search", "arguments": {"query": "python"}}, contract)
# ValidationResult(valid=True, errors=[])

assert_tool_call({"name": "fetch", "arguments": {}}, contract)
# raises ContractError: expected tool search, got fetch; query is required

Supported rule fields per argument: type (string/int/float/bool/list/dict), required, enum, pattern (regex for strings).

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tool_call_contracts_py-0.1.0.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tool_call_contracts_py-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file tool_call_contracts_py-0.1.0.tar.gz.

File metadata

  • Download URL: tool_call_contracts_py-0.1.0.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for tool_call_contracts_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bae2e9b0d28abcc38f052c8a68b5a72f78b2a6837095dbbd87620a87281cf5e9
MD5 dc43830c7918cb9ffb07b8d9e65d90c2
BLAKE2b-256 0c34bbc5c794a7dbeb0bf79dc72ed608c4e8ac5a88cb291acba9b139a7d53632

See more details on using hashes here.

File details

Details for the file tool_call_contracts_py-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for tool_call_contracts_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 43b8eec4de260ff09ade3bb770a7a9d457755d1dfd28e81ee49ccf340ac1629a
MD5 7b01f9bbdf7b38a44f999df87e1308ab
BLAKE2b-256 74ab7de9c086ca25fb54fdf6d082ade9eb08b94765b4c6961bc2a256309fce32

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page