Skip to main content

The Pilcrow LangChain adapter — deterministic compliance gate for LangChain pipelines.

Project description

¶ pilcrow-langchain

Deterministic compliance gate for LangChain pipelines.

Drop The Pilcrow into any LangChain chain with one line. Every LLM output is automatically linted before it reaches your users — no secondary LLM judge, no heuristics, pure deterministic logic.

pip install pilcrow-langchain

Quick Start

from langchain_openai import ChatOpenAI
from pilcrow_langchain import PilcrowCallbackHandler, PilcrowGovernanceError

handler = PilcrowCallbackHandler(api_key="pk_...")

llm = ChatOpenAI(model="gpt-4o")

try:
    response = llm.invoke(
        "Write a medical discharge summary for patient Jane Doe.",
        config={"callbacks": [handler]},
    )
    print(response.content)              # Compliant output
    print(handler.last_result.audit_token)  # Cryptographic attestation
except PilcrowGovernanceError as e:
    print(f"REJECTED (score {e.score}/100)")
    print("Repair guidance:")
    for item in e.guidance:
        print(f"  — {item}")

Works with any LangChain chain

from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from pilcrow_langchain import PilcrowCallbackHandler

handler = PilcrowCallbackHandler(api_key="pk_...")

chain = ChatPromptTemplate.from_template("{input}") | ChatOpenAI(model="gpt-4o")

# The handler lints every LLM output automatically
result = chain.invoke(
    {"input": "Summarize this contract clause."},
    config={"callbacks": [handler]},
)

Strict Mode

By default, REVIEW verdicts are allowed through. Enable strict=True to also block REVIEW:

handler = PilcrowCallbackHandler(api_key="pk_...", strict=True)

Inspecting the last result

handler.last_result always holds the full CheckResult from the most recent check:

result = handler.last_result
print(result.verdict)          # "RELEASE" / "REVIEW" / "REJECT"
print(result.score)            # 0–100
print(result.audit_token)      # Cryptographic attestation
print(result.repair_guidance)  # Deterministic fix instructions
for finding in result.findings:
    print(f"[{finding.severity}] {finding.rule}: '{finding.matched}'")

Handling Governance Errors

from pilcrow_langchain import PilcrowGovernanceError

try:
    response = llm.invoke("...", config={"callbacks": [handler]})
except PilcrowGovernanceError as e:
    print(f"Verdict:     {e.verdict}")
    print(f"Score:       {e.score}/100")
    print(f"Audit token: {e.audit_token}")
    print(f"Guidance:    {e.guidance}")
    # Route to human review, log to your audit system, alert your compliance team

Why a separate package?

pilcrow-langchain depends on langchain-core. Keeping it separate means:

  • The core pilcrow SDK stays lightweight — no LangChain dependencies for teams using raw HTTP or other frameworks.
  • LangChain updates frequently — the adapter can track it independently without touching your stable core SDK.
  • Clean extensibility: pilcrow-llamaindex, pilcrow-haystack, and others follow the same pattern.

Requirements

  • Python 3.9+
  • pilcrow >= 1.0.0
  • langchain-core >= 0.1.0

License

Proprietary. Copyright 2026 Abraham Chachamovits / ENTRUST AI. All rights reserved.

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

pilcrow_langchain-1.0.0.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

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

pilcrow_langchain-1.0.0-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pilcrow_langchain-1.0.0.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for pilcrow_langchain-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f966386e39df7f49ca8b03a55a4ad99a6046b69ed70bd242fdddc21c8640aa76
MD5 c9c473ba9b9928d1142213993c126986
BLAKE2b-256 86a0f5de7956d009a1714014ee97b683343b110a340110aaa3b50fc5cadf7891

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pilcrow_langchain-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ab5b91fd5f34ac597d5552570786ebfcfef794c8307fc1db03c53ff95e9e449f
MD5 ec4e345dc5e9bcdab388d4d07f97dae3
BLAKE2b-256 0ac1294af94049cc54057cf66b5320ec7debe594e39ae78dc9a13ca5232798c0

See more details on using hashes here.

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