Skip to main content

Privaro Python SDK

Privacy Infrastructure for Enterprise AI — iCommunity Labs

The Privaro SDK intercepts prompts and agent steps, tokenises PII before any LLM call, and generates a blockchain-certified audit trail per interaction.

pip install privaro
pip install privaro[async]   # for AsyncAgentRun + CrewAI support

Quick Start

Protect a prompt

import privaro

privaro.init(
    api_key="prvr_your_key",
    pipeline_id="your-pipeline-uuid"
)

result = privaro.protect("Patient: María García, DNI 34521789X, Tel: 612 345 678")
print(result.protected)
# "Patient: [NM-0001], DNI [ID-0001], Tel: [PH-0001]"

response = your_llm.complete(result.protected)   # LLM never sees real PII

Full-cycle relay

Let Privaro protect the messages, call your configured LLM (the key you set in /app/admin/providers), and de-tokenise the response for you.

relay() — single response

result = privaro.relay([
    {"role": "user", "content": "Soy Juan Pérez, ¿podéis confirmarme mi cita?"}
])
print(result["response"])  # already de-tokenised, ready to show

relay_stream() — for chat UIs

Yields text deltas as the LLM generates them (SSE under the hood). Deltas are already de-tokenised — never a raw token, safe to render directly.

for delta in privaro.relay_stream([
    {"role": "user", "content": "Soy Juan Pérez, ¿podéis confirmarme mi cita?"}
]):
    print(delta, end="", flush=True)

Supported for streaming today: OpenAI, Azure OpenAI, Anthropic. Other providers raise PrivaroError — use relay() (non-streaming) for those. idempotency_key is not supported on relay_stream() (replaying a completed stream doesn't have the same semantics as retrying a short response) — use relay() if you need idempotent retries.

Consistent tokens across turns — conversation_id

Pass your own conversation/session id to protect() or relay()/relay_stream() and the same PII value always gets the same token within that conversation:

result = privaro.relay(messages, conversation_id="your-session-id")

Output-direction scanning — protect_output()

relay()/relay_stream() already scan the LLM's response for you (Privaro makes the LLM call itself there). If instead you call protect() and then hit your own LLM directly, use protect_output() to scan that response before returning it to your end user — RAG retrieval, tool-call results, and model memorization can all leak PII that was never in the original prompt.

Requires the pipeline to have output scanning enabled (dashboard: Pipelines → Settings → Output scanning) — otherwise raises OutputScanningDisabledError rather than silently skipping the scan.

result = privaro.protect_output(
    llm_response_text,
    conversation_id="your-session-id",  # same id used for protect()
)
print(result.protected)       # send this to your end user
print(result.scan_mode)       # "shadow" (informational) | "enforce"
print(result.response_modified)

Agent Support

Sync — AgentRun (LangChain, direct)

from privaro.agent import AgentRun

with AgentRun(api_key="prvr_...", pipeline_id="...") as run:
    # Step 1: protect before LLM
    step = run.protect([
        {"role": "user", "content": "Review contract for Juan García, IBAN ES91 2100 0418 4502 0005 1332"}
    ])
    
    # Step 2: send protected messages to LLM
    response = your_llm.complete(step.protected_messages)
    
    # Step 3: detokenise final output
    final = run.reveal(response)
    print(f"Risk score: {step.risk_score}")    # 0.0–1.0
    print(f"PII detected: {step.total_pii_detected}")

Async — AsyncAgentRun (CrewAI, asyncio, n8n)

import asyncio
from privaro.async_client import AsyncAgentRun

async def analyse_document(text: str) -> str:
    async with AsyncAgentRun(
        api_key="prvr_...",
        pipeline_id="...",
        agent_framework="crewai",
    ) as run:
        step = await run.protect(text)
        response = await your_llm.acomplete(step.first_content)
        return await run.reveal(response)

result = asyncio.run(analyse_document("Client: Ana López, DNI 87654321X"))

pip install "privaro[langchain]"

from privaro import PrivaroClient
from privaro.integrations.langchain import privaro_guard, PrivaroDocumentTransformer, PrivaroRetriever

client = PrivaroClient(api_key="prvr_...", pipeline_id="...")
chain = privaro_guard(prompt | llm | StrOutputParser(), client)       # mask in -> LLM -> reveal out
docs = PrivaroDocumentTransformer(client).transform_documents(raw)    # mask before embedding
rag = PrivaroRetriever(vectorstore.as_retriever(), client)            # mask retrieved chunks (+ allowed_roles ACL)

privaro.agent.PrivaroCallbackHandler is deprecated: LangChain callbacks cannot rewrite what a model receives, so it does not protect chat models. Use the Runnables above.

LlamaIndex

pip install "privaro[llamaindex]"

from privaro.integrations.llamaindex import PrivaroNodePostprocessor, PrivaroTransform

engine = index.as_query_engine(node_postprocessors=[PrivaroNodePostprocessor(client)])
pipeline = IngestionPipeline(transformations=[SentenceSplitter(), PrivaroTransform(client), embed_model])

Any OpenAI-compatible client — base_url swap

from openai import OpenAI
client = OpenAI(base_url="https://api.privaro.ai/v1", api_key="prvr_...",
                default_headers={"X-Privaro-Pipeline": "<pipeline-uuid>"})

Optional headers: X-Privaro-Mode (tokenise | mask | block), X-Privaro-Conversation (uuid). Streaming supported; your LLM provider key must be configured in Privaro (BYOK). Tool-calling is not proxied by this endpoint yet.

client.detokenize(text, conversation_id)

Reverse Privaro tokens using the same conversation_id that produced them (protect(..., conversation_id=...)).

CrewAI Tool

from privaro.async_client import CrewAIPrivaroTool
from crewai import Tool

class ContractAnalyser(CrewAIPrivaroTool):
    name = "Contract Analyser"
    description = "Analyses contracts with built-in PII protection"

    async def _execute(self, protected_input: str, run) -> str:
        # protected_input has PII tokenised — safe to send to LLM
        return await your_llm.acomplete(protected_input)

tool = ContractAnalyser(api_key="prvr_...", pipeline_id="...")

ProtectResult

result = privaro.protect("...")

result.protected        # Tokenised prompt — send this to your LLM
result.original         # Original text (never sent to Privaro servers)
result.has_pii          # True if PII was detected
result.is_safe          # True if all PII masked, no leaks
result.risk_level       # "high" | "medium" | "low"
result.risk_score       # 0.0–1.0
result.gdpr_compliant   # True if all critical PII was masked
result.total_detected   # Count of PII entities found
result.total_masked     # Count of PII entities masked
result.processing_ms    # Latency in milliseconds
result.audit_log_id     # Supabase audit log UUID
result.summary()        # One-line log string

Exceptions

from privaro.exceptions import (
    PrivaroError,                # Base exception
    AuthError,                   # Invalid or missing API key
    PipelineNotFoundError,       # Pipeline UUID not found
    PolicyBlockError,            # Request blocked by policy
    RateLimitError,               # Too many requests
    ProxyUnavailableError,        # Cannot reach proxy
    OutputScanningDisabledError,  # protect_output() called on a pipeline
                                  # that hasn't enabled output scanning
)

try:
    result = privaro.protect("...")
except PolicyBlockError:
    # PII blocked by policy — do not proceed
    pass
except AuthError:
    # Check API key
    pass

Requirements

  • Python 3.9+
  • No required dependencies (uses urllib only for sync client)
  • aiohttp>=3.8 for async support (pip install privaro[async])

Metadata

Release files for privaro 0.8.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 privaro 0.8.0
File Size Uploaded Provenance Actions
privaro-0.8.0.tar.gz 28.7 kB With provenance Details for privaro-0.8.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for privaro 0.8.0
File Interpreter ABI Platform Actions
privaro-0.8.0-py3-none-any.whl Python 3 none any Details for privaro-0.8.0-py3-none-any.whl

Total release size: 55.3 kB

Release files / privaro-0.8.0.tar.gz

Download URL privaro-0.8.0.tar.gz
Size 28.7 kB
Tags Source
SHA-256 checksum
How to use checksums
f3ffe573cb6ac969db9f3d1cdc4ed151d249c700ed197b16bdfe5fd935468e4c
BLAKE2b-256 checksum
How to use checksums
fd608505adc13b91742360e9a3fc02673eb8641597b8749f437cdd41c2e5ebdb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 24, 2026.

Transparency log

Release files / privaro-0.8.0-py3-none-any.whl

Download URL privaro-0.8.0-py3-none-any.whl
Size 26.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4d377e3741638660add13cd5c4dc557141fdd9fb8565176f26ef1699fda81ac1
BLAKE2b-256 checksum
How to use checksums
967f4e7468f9956389c462a950fbecd34917384c37717103f85fd7a37fbf9370
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 24, 2026.

Transparency log

Security for privaro 0.8.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 privaro-0.8.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 Nov 24, 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.

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