Skip to main content

langchain-starring

A LangChain callback that blocks malicious agent tool-call chains. Content moderation cares what the Agent says — this cares what the Agent does.

一个 LangChain 回调处理器:在工具执行前累积行为链,判定「每一步都合法、串起来就是攻击」的链式攻击(如 read_sms → send_credentials),命中即熔断。

为什么需要它

单步安全工具拦不住这条链:

read_sms          ← 读用户短信(客服的常规权限,白名单内)
send_credentials  ← 把验证码发出去

每一步都合法,串起来就是验证码外泄。传统基于单步规则的防护是盲区,langchain-starring 专注行为链关联分析。

安装

pip install langchain-starring

用法(零代码修改,一行挂载)

from langchain.agents import AgentExecutor, create_tool_calling_agent
from langchain_openai import ChatOpenAI
from starring import StarRingCallbackHandler

agent = create_tool_calling_agent(ChatOpenAI(), tools, prompt)

executor = AgentExecutor(
    agent=agent,
    tools=tools,
    # 一行挂载,行为链危险时自动抛 StarRingBlockedError
    callbacks=[StarRingCallbackHandler()],
)

executor.invoke({"input": "帮我查一下退款"})
# 当 Agent 尝试 read_sms -> send_credentials 时,第二个工具调用抛出异常,验证码不外发

能力

能力 说明
行为链判定 累积最近 N 步工具调用,判「组合起来是否危险」
参数闸门 路径穿越、超额转账、域名黑名单、批量次数
未知动作熔断 幻觉出的工具名直接拒绝(fail-closed)
自定义映射 action_map 把自定义工具名映射到标准动作

配置

handler = StarRingCallbackHandler(
    max_history=6,                          # 行为链最多保留 6 步
    action_map={"search_web": "external_http"},  # 工具名映射
    config={"amount_max": 5000, "path_deny": [".."]},  # 参数闸门阈值
    raise_on="block_fuse",                  # block 和 fuse 都熔断
)

与竞品的差异

interven-langchain、iris-security、ActShield 等方案主要做单步检测(这一句话有没有毒、这个工具危不危险)。langchain-starring 的差异化在于:

抓住「每一步都合法,但串联起来就是攻击」的复杂场景——这是单步规则覆盖不了的盲区。

更多


MIT © 2026 Star-Ring AI Behavior Security Lab

Metadata

Release files for langchain-starring 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for langchain-starring 0.1.0
File Size Uploaded Provenance Actions
langchain_starring-0.1.0.tar.gz 8.4 kB Without provenance Details for langchain_starring-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for langchain-starring 0.1.0
File Interpreter ABI Platform Actions
langchain_starring-0.1.0-py3-none-any.whl Python 3 none any Details for langchain_starring-0.1.0-py3-none-any.whl

Total release size: 17.9 kB

Release files / langchain_starring-0.1.0.tar.gz

Download URL langchain_starring-0.1.0.tar.gz
Size 8.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2aee1f1d0fa6f2fb634e4cde978b77528f6b18716007312ff09ba647fe95ef47
BLAKE2b-256 checksum
How to use checksums
5a39f0ca4dec00645b07cd45aec878569e14665d96511cef47f7b5133756f97f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.7

Release files / langchain_starring-0.1.0-py3-none-any.whl

Download URL langchain_starring-0.1.0-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
893611b4d65fad9e8bfc9d36573aa409cc33be5c6e6b38c9874540010c862288
BLAKE2b-256 checksum
How to use checksums
21fc2aa4a3b5d969a9971568a37286eb6bfc548f7bbfa1f437a8d43d64abdfdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.7

Security for langchain-starring 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page