Skip to main content

Official Palveron LangChain integration — automatic policy enforcement, PII masking, and audit trails for every LLM call.

Project description

palveron-langchain

PALVERON AI Governance adapter for LangChain — automatic policy checks, PII masking, and audit trails for every LLM call in your pipeline.

PyPI License


Add one callback handler. Every prompt, every tool call, every LLM output gets checked against your PALVERON governance policies. PII is detected. Secrets are caught. Blocked requests raise exceptions before they reach the model.

Installation

pip install palveron-langchain

Quick Start

from palveron_langchain import PalveronCallbackHandler
from langchain_openai import ChatOpenAI

# Create the governance handler
handler = PalveronCallbackHandler(api_key="pv_live_xxx")

# Attach to any LangChain component
llm = ChatOpenAI(model="gpt-4o", callbacks=[handler])

# Every call is now governed
result = llm.invoke("Transfer $50,000 to account DE89370400440532013000")
# → PalveronGovernanceError: Blocked — PII detected (IBAN)

What Gets Checked

Event When What
on_llm_start Before text completion Prompt text
on_chat_model_start Before chat model call All messages concatenated
on_tool_start Before tool execution Tool name + input
on_llm_end After generation (optional) LLM output text

Configuration

handler = PalveronCallbackHandler(
    api_key="pv_live_xxx",
    base_url="https://gateway.palveron.com",  # On-prem endpoint
    check_prompts=True,       # Check inputs before LLM (default: True)
    check_outputs=False,      # Check LLM outputs (default: False)
    check_tools=True,         # Check tool inputs (default: True)
    raise_on_block=True,      # Raise exception on BLOCKED (default: True)
    fail_open=False,          # Allow calls when gateway down (default: False)
    metadata={"team": "ml"},  # Extra metadata on every trace
)

Behavior on Decisions

Decision raise_on_block=True raise_on_block=False
ALLOWED Call proceeds Call proceeds
MODIFIED Call proceeds, PII redaction logged Call proceeds, PII redaction logged
BLOCKED Raises PalveronGovernanceError Logs warning, call proceeds
ERROR Depends on fail_open Depends on fail_open

Note: LangChain callbacks are observational — they cannot modify prompts in-flight. For full input rewriting (PII masking before the LLM sees it), use the PALVERON Gateway Proxy.

Governance Records

Access the audit trail programmatically:

# After running your chain
print(f"Blocked: {handler.blocked_count}")
print(f"Trace IDs: {handler.trace_ids}")

for record in handler.records:
    print(f"{record.event}: {record.decision} ({record.latency_ms:.0f}ms) — {record.trace_id}")

Error Handling

from palveron_langchain import PalveronCallbackHandler, PalveronGovernanceError

handler = PalveronCallbackHandler(api_key="pv_live_xxx")

try:
    result = llm.invoke("Send SSN 123-45-6789 to the client", config={"callbacks": [handler]})
except PalveronGovernanceError as e:
    print(e.decision)   # "BLOCKED"
    print(e.trace_id)   # "trc_abc123"
    print(e.reason)     # "PII detected: Social Security Number"

With Agents

from langchain.agents import create_react_agent

handler = PalveronCallbackHandler(api_key="pv_live_xxx", check_tools=True)

agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, callbacks=[handler])

# Both LLM calls AND tool executions are governed
result = agent_executor.invoke({"input": "Delete all customer records"})

With Chains (LCEL)

from langchain_core.prompts import ChatPromptTemplate

handler = PalveronCallbackHandler(api_key="pv_live_xxx")

chain = ChatPromptTemplate.from_template("Summarize: {text}") | llm
result = chain.invoke({"text": sensitive_doc}, config={"callbacks": [handler]})

Requirements

  • Python 3.9+
  • palveron-sdk >= 0.5.0
  • langchain-core >= 0.2.0

Links

License

Apache 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

palveron_langchain-1.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

palveron_langchain-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file palveron_langchain-1.0.0.tar.gz.

File metadata

  • Download URL: palveron_langchain-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for palveron_langchain-1.0.0.tar.gz
Algorithm Hash digest
SHA256 7790b7f33941da48a2af7826df34c856e141f5381fa37b90c54d76455e50fea5
MD5 e4ea1f48a6129b53fa00757baded0bb2
BLAKE2b-256 d3668b04354d872b3898042a391faab827b205e31f0083905121d3e378a1c652

See more details on using hashes here.

Provenance

The following attestation bundles were made for palveron_langchain-1.0.0.tar.gz:

Publisher: publish.yml on palveron/adapter-langchain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file palveron_langchain-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for palveron_langchain-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d12e6050742df5825c55a9c812a4fc26281536fcc8273cafd73ca9c9cbb6267d
MD5 dec4b7891577c11560901b853f6954c3
BLAKE2b-256 cb563fbc3f207d02a3425b2f6133fe002d338e0bd971915df0cd3d7589c52c54

See more details on using hashes here.

Provenance

The following attestation bundles were made for palveron_langchain-1.0.0-py3-none-any.whl:

Publisher: publish.yml on palveron/adapter-langchain

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page