Sunglasses is a filter that sits ahead of your LangChain agent. Always ON. Every input the agent would process — the callback scans first. No opt-in. This page walks through the LangChain wiring.

Who this page is for

LangChain devs building custom agents on top of ChatAnthropic, ChatOpenAI, or any other LangChain-wrapped LLM. Drop-in callback integration — every input the agent processes runs through the filter first, before the LLM sees it.

The command

from sunglasses.integrations.langchain import SunglassesCallback

Mandatory filter for every LangChain input. Drop the callback into your LLM wrapper. Every input the agent processes — user messages, tool responses, retrieved documents — is scanned before the LLM sees it.

Benefit: This is framework-level enforcement. Unlike MCP (agent opts in per call), the callback fires on every single input. 100% coverage within your LangChain pipeline.

Full walkthrough coming next. This is an identity-first scaffold — the core command and wiring pattern are ready. The full step-by-step code walkthrough, integration examples, and troubleshooting section are being drafted now. Check back shortly.

FAQ

How do I add prompt injection protection to a LangChain agent?

Import SunglassesCallback from sunglasses.integrations.langchain and pass it to your LLM wrapper's callbacks argument. Every input the agent processes will be scanned through the Sunglasses filter before the LLM sees it.

Is the LangChain callback mandatory by default?

Yes. Unlike MCP (where the agent decides when to call the scan tool), a LangChain callback fires on every input by framework design. 100% enforcement within the LangChain pipeline.

Does this work with ChatAnthropic, ChatOpenAI, and Google Gemini in LangChain?

Yes. The Sunglasses callback works with any LangChain LLM wrapper that accepts callbacks — ChatAnthropic, ChatOpenAI, ChatGoogleGenerativeAI, and others.

Does the filter add latency to my LangChain chain?

Average scan time is 0.26ms. The filter runs synchronously before the LLM call, so it adds well under a millisecond to most chain invocations.

Do I need an API key for Sunglasses?

No. Sunglasses runs locally as a Python library. No API key, no cloud service, no telemetry. Install via pip in your project's virtual environment.

Where this wiring fits

Sunglasses is one filter with four wiring options. This page covers the LangChain path. Other wiring paths:

Same filter underneath. Different wiring based on your stack.