KoraSafe Python SDK — inline guardian scans + chain-of-thought trace capture for Python agents
Project description
KoraSafe Python SDK
Two surfaces in one package:
KoraSafeClient— inline guardian inspection (scan, gate, submit findings). Metadata-only transport.kora_trace— capture agent chain-of-thought (plan, LLM calls, tool calls, reasoning, human approvals) and ship to the KoraSafe audit log.
pip install korasafe-sdk
export KORASAFE_API_KEY=ks_live_...
kora_trace — chain-of-thought capture
10-line FastAPI example:
from fastapi import FastAPI
from korasafe import init_trace, kora_trace
init_trace()
app = FastAPI()
@app.post("/classify")
def classify(text: str) -> dict[str, str]:
with kora_trace.run("classify_claim"):
kora_trace.plan(["look up policy", "score risk", "route"])
kora_trace.llm_call(provider="openai", model="gpt-4o", input=text, output="tier=gold", input_tokens=120, output_tokens=30)
kora_trace.tool_call(name="policy_lookup", parameters={"id": "pol-7"}, response={"tier": "gold"}, status="ok")
kora_trace.human_approval(reviewer_id="user-42", decision="approved")
return {"tier": "gold"}
Events appear in the KoraSafe audit log within 5 seconds.
API
| Method | Purpose |
|---|---|
kora_trace.run(task_name) |
Context manager. Opens a trace; run_start + run_end events bracket the block. Nested method calls auto-attach via contextvars. |
@kora_trace.trace(task_name) |
Decorator equivalent of run. Works on sync and async functions. |
kora_trace.plan(steps, reasoning=None) |
Log initial plan. steps can be strings or {step, description} dicts. |
kora_trace.llm_call(provider, model, input, output, input_tokens=, output_tokens=, total_tokens=, cost_usd=, duration_ms=, status=, error=) |
Log an LLM invocation. Tokens auto-sum if total_tokens omitted. |
kora_trace.tool_call(name, parameters=, response=, status=, duration_ms=, error=) |
Log a tool or external API call. |
kora_trace.human_approval(reviewer_id, decision, notes=, approval_chain=) |
Log a HITL decision. |
kora_trace.flush() |
Force-flush buffered events. |
kora_trace.close() |
Drain buffer + close HTTP client. |
init_trace(**kwargs) reinitializes the singleton with overrides (api_key, endpoint, batch_size=10, flush_interval_s=5, timeout_s=10, max_retries=3, disabled=False, logger=, http_client=).
Calling plan / llm_call / tool_call / human_approval outside a run() context raises RuntimeError — wrap your agent loop first.
KoraSafeClient — guardian inspection
from korasafe import KoraSafeClient, withKoraSafeScan
client = KoraSafeClient()
@withKoraSafeScan(client=client, context={"system_id": "claims-agent"})
def answer_claim(prompt: str) -> str:
return "approved"
result = client.scan("Does this contain PII?", {"system_id": "claims-agent"})
gate = client.gate({"action": "payment_approval", "risk_tier": "high"})
finding = client.submit_finding({"guardian_id": "pii", "title": "PII found", "severity": "high"})
Raw strings passed to scan() or the decorator are hashed locally. The SDK sends content hash, byte length, direction, surface, labels, and caller metadata rather than prompt or response bodies.
Frameworks
LangChain:
from korasafe import KoraSafeCallback, KoraSafeClient
callbacks = [KoraSafeCallback(client=KoraSafeClient(), context={"system_id": "claims-agent"})]
LlamaIndex:
from korasafe import KoraSafeClient, KoraSafeLlamaIndexMiddleware
query_engine = KoraSafeLlamaIndexMiddleware(KoraSafeClient()).wrap_query_engine(query_engine)
Development
cd packages/sdk-python
python -m pip install -e ".[dev]"
ruff check .
mypy .
coverage run -m pytest
coverage report
python -m build
Publishing uses GitHub OIDC trusted publishing to PyPI from sdk-python-v* tags.
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 korasafe_sdk-0.2.0.tar.gz.
File metadata
- Download URL: korasafe_sdk-0.2.0.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
66ae2f1d4e80d07a4caefb86645f8c8c0f313eb1bf93778c138692fbd2afc009
|
|
| MD5 |
df1404a4022f0bf40e6ff19014fde1be
|
|
| BLAKE2b-256 |
8526254211fb5852b44a147d4672387f12a509226e30d5b010182e639e56343b
|
Provenance
The following attestation bundles were made for korasafe_sdk-0.2.0.tar.gz:
Publisher:
publish-sdk-python.yml on korasafe/platform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
korasafe_sdk-0.2.0.tar.gz -
Subject digest:
66ae2f1d4e80d07a4caefb86645f8c8c0f313eb1bf93778c138692fbd2afc009 - Sigstore transparency entry: 1726618576
- Sigstore integration time:
-
Permalink:
korasafe/platform@86204b883bee10e8d38166cc2f1e9e044e131cbb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/korasafe
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-python.yml@86204b883bee10e8d38166cc2f1e9e044e131cbb -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file korasafe_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: korasafe_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.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 |
fd3b9a1acc492d27cdf6908553b142a799ad073b6f3f704a33fb8015c8bfc1f3
|
|
| MD5 |
1214600e02ac58bceccbff4791f54ea8
|
|
| BLAKE2b-256 |
64536ff6da2e22e09b7e25c8d6f383b968effd1861465fb47c62578b8ed2e6a5
|
Provenance
The following attestation bundles were made for korasafe_sdk-0.2.0-py3-none-any.whl:
Publisher:
publish-sdk-python.yml on korasafe/platform
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
korasafe_sdk-0.2.0-py3-none-any.whl -
Subject digest:
fd3b9a1acc492d27cdf6908553b142a799ad073b6f3f704a33fb8015c8bfc1f3 - Sigstore transparency entry: 1726618644
- Sigstore integration time:
-
Permalink:
korasafe/platform@86204b883bee10e8d38166cc2f1e9e044e131cbb -
Branch / Tag:
refs/heads/main - Owner: https://github.com/korasafe
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdk-python.yml@86204b883bee10e8d38166cc2f1e9e044e131cbb -
Trigger Event:
workflow_dispatch
-
Statement type: