langchain - ✅(Solved) Fix Add ForceField AI security integration (langchain-forcefield) [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#36357Fetched 2026-04-08 01:48:42
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Participants
Timeline (top)
closed ×1commented ×1cross-referenced ×1labeled ×1

ForceField is an AI security SDK that scans prompts for injection attacks, PII leaks, jailbreaks, and 13+ attack categories. We'd like to add it as a LangChain partner integration.

Error Message

  • PromptBlockedError: exception raised when a malicious prompt is detected

Root Cause

ForceField is an AI security SDK that scans prompts for injection attacks, PII leaks, jailbreaks, and 13+ attack categories. We'd like to add it as a LangChain partner integration.

Fix Action

Fixed

PR fix notes

PR #36356: feat(partners): add langchain-forcefield integration package

Description (problem / solution / changelog)

Fixes #36357

New Partner: ForceField AI Security

ForceField is an AI security SDK that scans prompts for injection attacks, PII leaks, jailbreaks, and 13+ attack categories. This PR adds a LangChain partner integration package.

What it does

  • ForceFieldCallbackHandler: LangChain callback that scans prompts before they reach the LLM and moderates outputs after generation
  • PromptBlockedError: raised when a malicious prompt is detected
  • Scans both on_llm_start (completions) and on_chat_model_start (chat models)
  • Output moderation via on_llm_end

Features

  • Zero config -- works offline, no API keys needed
  • 116 built-in attack prompts for security evals
  • 100%% detection rate with ML model

Install

pip install langchain-forcefield

Usage

from langchain_openai import ChatOpenAI
from langchain_forcefield import ForceFieldCallbackHandler

handler = ForceFieldCallbackHandler(sensitivity='high')
llm = ChatOpenAI(callbacks=[handler])
llm.invoke('Hello')

Links

Tests

  • Unit tests for imports, handler creation, injection blocking, safe prompt passthrough, and on_block callback
  • Integration test placeholder

Changed files

  • libs/partners/forcefield/LICENSE (added, +21/-0)
  • libs/partners/forcefield/Makefile (added, +45/-0)
  • libs/partners/forcefield/README.md (added, +59/-0)
  • libs/partners/forcefield/langchain_forcefield/__init__.py (added, +5/-0)
  • libs/partners/forcefield/langchain_forcefield/callback.py (added, +156/-0)
  • libs/partners/forcefield/langchain_forcefield/py.typed (added, +1/-0)
  • libs/partners/forcefield/pyproject.toml (added, +88/-0)
  • libs/partners/forcefield/scripts/check_imports.py (added, +10/-0)
  • libs/partners/forcefield/scripts/lint_imports.sh (added, +2/-0)
  • libs/partners/forcefield/tests/__init__.py (added, +1/-0)
  • libs/partners/forcefield/tests/integration_tests/__init__.py (added, +1/-0)
  • libs/partners/forcefield/tests/integration_tests/test_compile.py (added, +8/-0)
  • libs/partners/forcefield/tests/unit_tests/__init__.py (added, +1/-0)
  • libs/partners/forcefield/tests/unit_tests/test_callback.py (added, +79/-0)
  • libs/partners/forcefield/tests/unit_tests/test_imports.py (added, +13/-0)

Code Example

from langchain_openai import ChatOpenAI
from langchain_forcefield import ForceFieldCallbackHandler

handler = ForceFieldCallbackHandler(sensitivity='high')
llm = ChatOpenAI(callbacks=[handler])
llm.invoke('Hello')
RAW_BUFFERClick to expand / collapse

Feature Request: ForceField Partner Integration

Description

ForceField is an AI security SDK that scans prompts for injection attacks, PII leaks, jailbreaks, and 13+ attack categories. We'd like to add it as a LangChain partner integration.

What it provides

  • ForceFieldCallbackHandler: LangChain callback that scans prompts before they reach the LLM and moderates outputs after generation
  • PromptBlockedError: exception raised when a malicious prompt is detected
  • Works on both on_llm_start (completions) and on_chat_model_start (chat models)
  • Output moderation via on_llm_end

Why it's useful for LangChain users

  • Zero config, works offline, no API keys needed
  • 116 built-in attack prompts for security evals
  • 100%% detection rate with ML model
  • Already published on PyPI: langchain-forcefield

Usage

from langchain_openai import ChatOpenAI
from langchain_forcefield import ForceFieldCallbackHandler

handler = ForceFieldCallbackHandler(sensitivity='high')
llm = ChatOpenAI(callbacks=[handler])
llm.invoke('Hello')

Links

I have a ready PR (#36356) with the full partner package including unit tests. Happy to reopen once this issue is approved.

extent analysis

Fix Plan

To integrate ForceField with LangChain, follow these steps:

  • Install the langchain-forcefield package using pip: pip install langchain-forcefield
  • Import the ForceFieldCallbackHandler class and create an instance with the desired sensitivity level
  • Create an LLM instance (e.g., ChatOpenAI) and pass the ForceFieldCallbackHandler instance to its callbacks parameter

Example Code

from langchain_openai import ChatOpenAI
from langchain_forcefield import ForceFieldCallbackHandler

# Create a ForceFieldCallbackHandler instance with high sensitivity
handler = ForceFieldCallbackHandler(sensitivity='high')

# Create a ChatOpenAI instance with the ForceFieldCallbackHandler
llm = ChatOpenAI(callbacks=[handler])

# Invoke the LLM with a prompt
llm.invoke('Hello')

Verification

To verify that the integration is working, test the LLM with a malicious prompt and check that a PromptBlockedError is raised. You can use the built-in attack prompts provided by ForceField for testing.

Extra Tips

  • Make sure to handle the PromptBlockedError exception in your application to provide a suitable response to the user.
  • Adjust the sensitivity level of the ForceFieldCallbackHandler instance according to your specific use case.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - ✅(Solved) Fix Add ForceField AI security integration (langchain-forcefield) [1 pull requests, 1 comments, 2 participants]