agentvet-py
Validate LLM-generated tool args before execution. Wraps tool functions with arg validation; raises ToolArgError with an LLM-friendly retry hint. Zero runtime dependencies.
Python port of @mukundakatta/agentvet.
Install
pip install agentvet-py
# pydantic adapter is optional:
pip install "agentvet-py[pydantic]"
Usage
from agentvet import vet, adapters, ToolArgError
def send_email_impl(args):
return "sent to " + args["to"]
schema = adapters.shape({"to": "str", "subject": "str", "body": "str?"})
send_email = vet(name="send_email", schema=schema, fn=send_email_impl)
# Happy path:
send_email({"to": "alice@example.com", "subject": "hello"}) # 'sent to alice@example.com'
# Bad args -> raises ToolArgError BEFORE the tool runs:
try:
send_email({"subject": "hello"}) # missing 'to'
except ToolArgError as err:
feedback = err.to_llm_feedback()
# Send `feedback` back to the LLM as a tool_result with is_error=True.
With pydantic
from pydantic import BaseModel, EmailStr
from agentvet import vet, adapters
class SendEmail(BaseModel):
to: EmailStr
subject: str
body: str | None = None
send_email = vet(
name="send_email",
schema=adapters.pydantic(SendEmail),
fn=lambda args: send_impl(**args),
)
Async tools
vet() preserves the sync/async nature of fn:
async def fetch_impl(args):
return await api.get(args["url"])
fetch = vet(name="fetch", schema=adapters.shape({"url": "str"}), fn=fetch_impl)
result = await fetch({"url": "https://example.com"})
API
vet(*, name, schema, fn, on_error=None) -> wrapped_fn
Wraps a tool function. Validates args BEFORE calling the tool; raises ToolArgError on failure (or invokes on_error(err, args) if provided -- return a non-None value to substitute as the tool's return).
validate(name, schema, args) -> ValidationResult
One-shot validation. Returns ValidationResult(ok=bool, value=..., error=ToolArgError | None).
adapters.shape(spec)
Tiny built-in shape checker. Spec format: {"field": "str"|"int"|"float"|"bool"|"list"|"dict", ...}. Suffix with ? for optional. Accepts JS sibling synonyms ("string", "number", "array", "object") too.
adapters.fn(predicate, error_builder?)
Predicate adapter. predicate(args) -> bool. error_builder may be a string or a callable returning a string.
adapters.pydantic(model_cls)
Wraps a pydantic v2 BaseModel. Requires pip install agentvet-py[pydantic].
adapters.zod(schema)
Compatibility shim for safeParse-style validators (rare in Python; included for parity).
ToolArgError
Carries tool, validation_error, args. .to_llm_feedback() returns the retry message you send back to the LLM.
API differences from the JS sibling
vet()uses keyword-only args (vet(name=..., schema=..., fn=..., on_error=...)).- Validators return Python dicts:
{"valid": True, "value": ...}/{"valid": False, "error": str}. adapters.pydanticreplacesadapters.zodas the natural Python adapter.- Type names in
shape()use Python conventions ("str","int","list","dict"); JS synonyms ("string","number","array","object") are accepted. ToolArgError.to_llm_feedback()issnake_case(mirrors JStoLLMFeedback()).
See the JS sibling's README for the full design notes.
Metadata
Release files for agentvet-py 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 | Provenance | |
|---|---|---|---|---|
| agentvet_py-0.1.0.tar.gz | 9.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| agentvet_py-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / agentvet_py-0.1.0.tar.gz
| Download URL | agentvet_py-0.1.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb51e0ed7918ff3cb3062be1e8ebb3dc4fa352de5596b7c6b661fd71cda7ab99
|
|
BLAKE2b-256 checksum How to use checksums |
a892c153442d0a61f6ac516c6a9cad5419b22442d292144e1cd0d8df77a5c195
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Release files / agentvet_py-0.1.0-py3-none-any.whl
| Download URL | agentvet_py-0.1.0-py3-none-any.whl |
|---|---|
| Size | 9.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f5eabf81ccfb5d4b06d2755c6724e6ea7979f6cf49639b4a9630fe5b2c1fce74
|
|
BLAKE2b-256 checksum How to use checksums |
026644632194a3bcf5005419bba30375c2aa01c8a05a88be45bc8da0f46af605
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.4
|
Security for agentvet-py 0.1.0
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.