SDK reference · Python SDK

prov.trace.assessments.create

prov.trace.assessments.create in Python SDK. Assess an action before it runs (POST /v1/trace/assessments).

Signature

prov.trace.assessments.create(action: dict, trace_id: Optional[str] = …, agent_id: Optional[str] = …, agent_session_id: Optional[str] = …, run_id: Optional[str] = …, context: Optional[dict] = …, findings: Optional[list] = …, wait: Optional[dict] = …, idempotency_key: Optional[str] = …, timeout: Optional[float] = …, max_retries: Optional[int] = …) -> Any

Parameters

actiondictRequired
trace_idOptional[str]
agent_idOptional[str]
agent_session_idOptional[str]
run_idOptional[str]
contextOptional[dict]
findingsOptional[list]
waitOptional[dict]
idempotency_keyOptional[str]
timeoutOptional[float]
max_retriesOptional[int]

Request fields

Idempotency-Keystringheader
Retry a create safely: the same key + request returns the stored response (24 h, per caller).
stageenum
action: before a tool call. One of action.
trace_idstring
The trace of the model call that produced the tool call.
agent_idstring
The registered agent.
agent_session_idstring
The agent's session (a rule's lock names it).
run_idstring
The run the action belongs to.
actionobjectRequired
The action the agent is about to take.
Show child attributes
toolstringRequired
The tool's name, such as payments.send.
riskenum
The risk class; read from the tool's name when left out. One of read, write, send, delete, pay.
amountinteger
The amount in minor units.
currencystring
ISO 4217.
payeestring
A payee ID or domain.
descriptionstring
What the action does, in words.
argsany
The tool's arguments: hashed (args_hash), never kept.
contextobject
What was in the model's context.
Show child attributes
untrusted_sourcesarray of enums
Kinds of untrusted content in the model's context.
findingsarray of objects
What your own guards reported. An unknown category is refused (finding_category_unknown).
Show child attributes
reporterenumRequired
Who reported it. One of lakera, bedrock_guardrails, prompt_shields, nemo_guardrails, own.
categoryenum
The finding's category. One of prompt_injection, indirect_injection, jailbreak, unsafe_output, pii_leak, malicious_link, credential_exfiltration, off_task.
confidencenumber
The reporter's confidence.
unansweredboolean
The guard ran and didn't answer (its finding.* facts are unavailable).
unassessedboolean
An SDK's record of a tool that ran while Provenance couldn't be reached.
unassessed_attimestamp
When the tool ran.
unassessed_reasonenum
Why it ran unchecked. One of unreachable, timeout, server_error.
droppedinteger
Records the SDK dropped before this one could be posted.
waitobject
Wait for a person to decide a challenge before answering.
Show child attributes
approval_sinteger
Seconds to wait (at most 25); the answer is still challenge if nobody decided.

Returns

Any The assessment.

HTTP operation

POST /v1/trace/assessments: Assess an action

Errors

Example

const step1 = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/policies`, {
  method: "PUT",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json" },
  body: JSON.stringify({
    "note": "ask before paying after an injected email; never delete",
    "document": {
      "rules": [
        {
          "id": "injected-email-payments",
          "label": "Payments after an injected email",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "pay"
            },
            {
              "fact": "context.untrusted_sources",
              "op": "contains",
              "value": "email"
            },
            {
              "fact": "finding.categories",
              "op": "contains",
              "value": "indirect_injection"
            }
          ],
          "require": {
            "approval": true
          }
        },
        {
          "id": "no-deletes",
          "label": "Deletes",
          "when": [
            {
              "fact": "action.risk",
              "op": "eq",
              "value": "delete"
            }
          ],
          "require": {
            "deny": true,
            "lock": true
          }
        }
      ]
    }
  }),
})).json();
const tracePolicyVersion = step1.version;
const data = await (await fetch(`${process.env.PROVENANCE_API}/v1/trace/assessments`, {
  method: "POST",
  headers: { Authorization: "Bearer prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5", "Content-Type": "application/json", "Idempotency-Key": "tsa-reference-1" },
  body: JSON.stringify({
    "agent_session_id": "ses_reference_trace",
    "action": {
      "tool": "payments.send",
      "amount": 185000,
      "currency": "USD",
      "payee": "acct_brindlecote_supplies",
      "description": "Pay invoice INV-2041"
    },
    "context": {
      "untrusted_sources": [
        "email"
      ]
    },
    "findings": [
      {
        "reporter": "own",
        "category": "indirect_injection",
        "confidence": 0.91
      }
    ]
  }),
})).json();

Was this page helpful? Send us feedback

LLM? Read llms.txt.