SDKs & integrations
LangChain
Keep personal data away from your LLM provider. User input, prompt variables and tool results are redacted before they reach the model, and the model’s answer (including tool-call arguments) comes back with the real values restored. A thin wrapper over the Obscate API.
Status: built and tested, not yet on PyPI. pip install langchain-obscate works once the package is published.
Known limitation: partial values come back wrong. If the model quotes only part of a redacted value (“your card ending in 7588”), restore can’t fix it: it matches whole tokens, and a fragment isn’t one. With fpe this fails silently and plausibly: the fake card looks like a real card, so its last four digits look real, and your user sees a confident, wrong statement about their own data. Assistants do this often.
Measured with real Claude (claude-haiku-5-5, 3 runs each, a small test): plain fpe prompt, 2 of 3 replies stated wrong card digits; fpe plus the instruction below, 0 of 3; tokenize, 0 of 3.
For user-facing output, add to your system prompt: “When you mention a card number, email or phone number, repeat it exactly and in full as given. Never abbreviate, mask or quote part of it.” Or use strategy="tokenize": models don’t split [CREDIT_CARD_1]. This is a boundary of any reversible-redaction approach: a fragment of a stand-in can never map back to a fragment of the original.
your input ──redact──▶ LLM sees "seab.yomog@tziwxuo.com", "[PERSON:…]" ──restore──▶ your user sees "ravi.kumar@example.com", "Ravi Kumar"
Quickstart (under 5 minutes)
pip install "langchain-obscate[examples]"
export OBSCATE_API_KEY=ob_... # free: 1,000 requests/month at https://obscate.com, no card
export ANTHROPIC_API_KEY=sk-ant-... # optional: without it the example uses a local stand-in LLM
python examples/quickstart.py
Output (real run with the stand-in LLM; the redacted values differ per key):
1) Your input:
Customer Ravi Kumar (email ravi.kumar@example.com phone +91 98765 43210) says card 4242 4242 4242 4242 was charged twice. ...
2) What the LLM receives:
[human] [PERSON:rug3juf…] (email seab.yomog@tziwxuo.com phone +91 45671 58378) says card 7982 1772 2838 5004 was charged twice. ...
3) Restored answer for your user:
... will confirm by email to ravi.kumar@example.com.
Any chat model, LLM or chain
Wrap it with with_obscate:
from langchain_obscate import with_obscate
safe_llm = with_obscate(ChatAnthropic(model="claude-haiku-5-5"))
safe_llm.invoke("Draft a reply to ravi@example.com about order 1182") # -> AIMessage, restored
chain = with_obscate(prompt | llm | StrOutputParser()) # prompt variables redacted
chain.invoke({"name": "Ravi Kumar", "email": "ravi@example.com"}) # -> str, restored
Agents: ObscateMiddleware
For create_agent, add the middleware. It redacts every model call: user messages, tool results, earlier turns and the system prompt. It restores the model’s reply before your tools run, so your tools receive real values and the provider never does.
pip install "langchain-obscate[agents]"
from langchain.agents import create_agent
from langchain_obscate import ObscateMiddleware
agent = create_agent("anthropic:claude-haiku-5-5", tools=[send_email],
middleware=[ObscateMiddleware()])
Why middleware rather than a callback: LangChain callbacks are observers. They are told what is sent to the model but cannot change it. Redaction has to rewrite the request, so it lives in a Runnable wrapper (chains) and in agent middleware (agents).
Explicit tools: ObscateRedactTool (fpe-redacts a text) and ObscateDetectTool (labels and counts only), for when the agent itself should scrub a record before passing it downstream.
Strategies
with_obscate(llm, strategy="tokenize", labels=["EMAIL", "PHONE"], min_confidence=0.5)
Default fpe (formats kept, values that can’t keep their format fall back to bracketed [LABEL:…] tokens, restore needs no map). tokenize and synthetic hold the token map in memory for one call. mask, hash and partial are one-way, so output stays redacted. See Strategies.
What to expect
- Cost: one Obscate request per model call (the whole conversation goes in one request, 1 unit per 100 KB). Restores are free. A 5-step agent run uses 5 units, so the free tier covers about 200 such runs a month.
- Streaming is buffered:
stream()on the wrapper yields one restored chunk at the end. With the agent middleware,stream_mode="messages"shows the raw, still-redacted tokens; the messages in agent state are restored. - Fails closed: if Obscate errors (network, quota, 503), the LLM is not called and
ObscateErroris raised. - Privacy: the package never logs, prints or writes the text, the detected values or the token map.
- Verified against the hosted API with real Claude (
claude-haiku-5-5): the wrapper, the agent middleware and the quickstart all restore correctly, with the partial-value limitation above. Setmax_tokensto 1024 or more: with less, a model that thinks first can use the whole budget and return no text.