Skip to content

[New Plugin] Add FangcunGuard guardrail#1737

Open
zhiyuanzeng99 wants to merge 1 commit into
Portkey-AI:mainfrom
zhiyuanzeng99:feat/fangcunguard-plugin
Open

[New Plugin] Add FangcunGuard guardrail#1737
zhiyuanzeng99 wants to merge 1 commit into
Portkey-AI:mainfrom
zhiyuanzeng99:feat/fangcunguard-plugin

Conversation

@zhiyuanzeng99

Copy link
Copy Markdown

[New Plugin] FangcunGuard guardrail

Closes #1736

Adds FangcunGuard as a guardrail plugin. FangcunGuard (by FangcunLeap) is a content-safety classifier that scores text into 10 safety categories — crimes, hate speech, self-harm, cybersecurity, extremism, and more — with a compact, low-latency, Chinese-optimized model.

Changes

  • plugins/fangcunguard/manifest.json — plugin definition (apiKey credential, optional customHost)
  • plugins/fangcunguard/scan.ts — handler supporting beforeRequestHook (scan prompt) and afterRequestHook (scan response)
  • plugins/fangcunguard/globals.ts — calls POST {baseURL}/guard/context with a Bearer token
  • plugins/fangcunguard/fangcunguard.test.ts — tests
  • Registered in plugins/index.ts

Behavior

The gateway verdict maps directly from the model's is_safe field (verdict = is_safe): safe content passes, unsafe content is flagged. The full classification (label, unsafe_score, confidence, model) is returned in data. Empty text passes without an API call.

Testing

npx jest plugins/fangcunguard/fangcunguard.test.ts5 passed against the live API:

✓ should fail (verdict false) when the api key is invalid
✓ should pass (verdict true) when the prompt is safe
✓ should fail (verdict false) when the prompt is unsafe
✓ should scan the model response on afterRequestHook
✓ should pass (verdict true) on empty text

prettier --check and tsc --noEmit both pass.

Getting a key

Sign up at https://www.fangcunleap.com or contact info@fangcunleap.com.

🤖 Generated with Claude Code

Adds FangcunGuard as a guardrail plugin. FangcunGuard (by FangcunLeap,
https://www.fangcunleap.com) is a content-safety classifier that scores
text into 10 safety categories (crimes, hate speech, self-harm,
cybersecurity, extremism, and more) with a compact, low-latency model.

- plugins/fangcunguard/{manifest.json,scan.ts,globals.ts}
- Single 'scan' function supporting beforeRequestHook (prompt) and
  afterRequestHook (response); verdict = is_safe
- Registered in plugins/index.ts
- Tests in fangcunguard.test.ts (5 passing against the live API)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add FangcunGuard guardrail plugin

1 participant