Skip to main content

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.

Metadata

Release files for korasafe-sdk 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for korasafe-sdk 0.2.0
File Size Uploaded Provenance Actions
korasafe_sdk-0.2.0.tar.gz 15.1 kB With provenance Details for korasafe_sdk-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for korasafe-sdk 0.2.0
File Interpreter ABI Platform Actions
korasafe_sdk-0.2.0-py3-none-any.whl Python 3 none any Details for korasafe_sdk-0.2.0-py3-none-any.whl

Total release size: 27.3 kB

Release files / korasafe_sdk-0.2.0.tar.gz

Download URL korasafe_sdk-0.2.0.tar.gz
Size 15.1 kB
Tags Source
SHA-256 checksum
How to use checksums
66ae2f1d4e80d07a4caefb86645f8c8c0f313eb1bf93778c138692fbd2afc009
BLAKE2b-256 checksum
How to use checksums
8526254211fb5852b44a147d4672387f12a509226e30d5b010182e639e56343b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Release files / korasafe_sdk-0.2.0-py3-none-any.whl

Download URL korasafe_sdk-0.2.0-py3-none-any.whl
Size 12.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fd3b9a1acc492d27cdf6908553b142a799ad073b6f3f704a33fb8015c8bfc1f3
BLAKE2b-256 checksum
How to use checksums
64536ff6da2e22e09b7e25c8d6f383b968effd1861465fb47c62578b8ed2e6a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

Security for korasafe-sdk 0.2.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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for korasafe_sdk-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 4, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page