Metadata-Version: 2.4
Name: pilcrow-langchain
Version: 1.0.1
Summary: The Pilcrow LangChain adapter — deterministic compliance gate for LangChain pipelines.
Author-email: Abraham Chachamovits <contact@entrustai.co>
License: Proprietary
Project-URL: Homepage, https://entrustai.co/pilcrow
Project-URL: Documentation, https://entrustai.co/pilcrow
Project-URL: API Reference, https://pilcrow.entrustai.co
Keywords: langchain,ai,governance,compliance,linting,enterprise,llm
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Quality Assurance
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: pilcrow>=1.0.0
Requires-Dist: langchain-core>=0.1.0

# ¶ 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

```python
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

```python
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`:

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

---

## Inspecting the last result

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

```python
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

```python
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.
