Metadata-Version: 2.4
Name: tryverdictguard-sdk
Version: 1.0.0
Summary: Python SDK for Verdict Core authenticated tool-intent evaluation
License-Expression: Apache-2.0
Project-URL: Homepage, https://www.tryverdictguard.com
Project-URL: Source, https://github.com/pnkr01/verdict/tree/master/verdict-platform/sdks/python
Project-URL: Issues, https://github.com/pnkr01/verdict/issues
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27.0
Requires-Dist: PyJWT>=2.9.0
Requires-Dist: cryptography>=43.0.0
Dynamic: license-file

# Verdict Python SDK

The synchronous `tryverdictguard-sdk` package (imported as `tryverdictguard_sdk`) evaluates proposed tool actions against Verdict Core. It returns the decision for your application to inspect; **it never invokes a downstream tool**.
Requires Python 3.11 or newer.

Licensed under Apache-2.0. See [LICENSE](./LICENSE).

## Install

```shell
pip install tryverdictguard-sdk
```

Provide credentials from Verdict Core directly or with `VERDICT_CLIENT_ID`,
`VERDICT_CLIENT_SECRET`, and `VERDICT_DPOP_PRIVATE_KEY`. The key value is the
base64url-encoded Ed25519 private key (`dpop_private_key_b64`). `VERDICT_BASE_URL`
defaults to `https://api.tryverdictguard.com`; set it explicitly for local development.

## Evaluate a proposed action

```python
from tryverdictguard_sdk import VerdictClient

with VerdictClient(agent_id="billing-agent") as verdict:
    decision = verdict.evaluate(
        tool_name="refund_payment",
        original_args={"payment_id": "pay_123", "amount_usd": 25.00},
        session_id="checkout-session-1001",
        end_user_id="user_456",
        risk_category="FINANCIAL",
        monetary_value_usd=25.00,
        pre_flight_snapshot={"payment_status": "captured"},
    )

    if decision.verdict_status == "ALLOWED":
        # Decide in application code whether and how to invoke the tool.
        pass
```

The evaluation request contains `correlation_id`, `agent_id`, `session_id`,
`end_user_id`, `tool_name`, `risk_category`, `monetary_value_usd`,
`original_args`, and `pre_flight_snapshot`. The session ID, end-user ID, risk
category, and monetary value are required on
every evaluation so separate users and sessions are not accidentally combined
or assigned guessed decision inputs; a correlation ID is generated when omitted.
`EvaluationResult` includes the execution ID, status,
policy/block information, computed diff, latency, RPM, session spend, and record
hash when supplied. Unknown status strings are preserved.

## Authenticated endpoints

Evaluation and each method below use a fresh Ed25519 DPoP proof on every request:

* `record_intent(tool_name, raw_arguments, llm_model, correlation_id=None)`
  posts to `/v1/telemetry/intent`.
* `wait_for_escrow(execution_id)` makes one GET to
  `/v1/guard/escrow/{execution_id}/wait`. It does not poll automatically; every
  non-2xx response, including HTTP 408, is surfaced as `VerdictAPIError`.
* `commit_snapshot(execution_id, execution_output)` posts to
  `/v1/guard/commit-snapshot`.

OAuth client-credentials tokens are obtained from `/oauth2/token`, cached until
shortly before expiry, and fetched again when needed. Protected requests use
`Authorization: DPoP <access_token>`. DPoP `htu` values exclude query strings
and fragments as specified by RFC 9449; request URLs retain their encoded query
and path components.

`VerdictAPIError` exposes `status_code`, `operation`, and an optional request ID.
`VerdictTransportError` identifies network and timeout failures. Error messages
avoid including response bodies or credentials. The client owns its HTTP
connection pool; use it as a context manager or call `close()`.
