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.1.tar.gz (5.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.1-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pilcrow_langchain-1.0.1.tar.gz
  • Upload date:
  • Size: 5.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.1.tar.gz
Algorithm Hash digest
SHA256 970f227d75166ce8fcc596aa18fcb42dcfaf954c6b0b4a25f6658cc9a311c0ff
MD5 2557681dfa6cfdbfc0ad9022eb8bb1e0
BLAKE2b-256 7e14a43113588f2f24aadff9b954ebd99dc6dfbc8b557355fcaae707abef974b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pilcrow_langchain-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c26d1fb2ffbb7f66a6da39a341f5b19a3cc8a56e0c9e738802f741acd335ae80
MD5 5deaf7af7fe26f6eca50943802cbaf05
BLAKE2b-256 5c9f8caeda358750e23418ad46275b4c92cff4d7247d2911555f2b28454f4a51

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