You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to add content moderation to LangChain/OpenAI agents?
#110
I am building an AI agent with LangChain and need to add content moderation. How can I filter profanity in user inputs and AI outputs?
Answer
Use glin-profanity with its built-in AI framework integrations:
Option 1: LangChain Tools
import{ChatOpenAI}from"@langchain/openai";import{createReactAgent}from"@langchain/langgraph/prebuilt";import{allProfanityTools}from"glin-profanity/ai/langchain";constagent=createReactAgent({llm: newChatOpenAI({modelName: "gpt-4o"}),tools: allProfanityTools});// Agent can now use profanity detection toolsconstresult=awaitagent.invoke({messages: [{role: "user",content: "Check this for profanity: [text]"}]});
Option 2: OpenAI Function Calling
importOpenAIfrom"openai";import{profanityTools,executeToolCall}from"glin-profanity/ai/openai";constclient=newOpenAI();constresponse=awaitclient.chat.completions.create({model: "gpt-4o",messages: [{role: "user",content: "Is this text safe?"}],tools: profanityTools});// Execute tool callsfor(consttoolCallofresponse.choices[0].message.tool_calls||[]){constresult=awaitexecuteToolCall(toolCall);console.log(result);}
Option 3: Vercel AI SDK
import{generateText}from"ai";import{openai}from"@ai-sdk/openai";import{profanityTools}from"glin-profanity/ai/vercel";constresult=awaitgenerateText({model: openai("gpt-4o"),tools: profanityTools,prompt: "Check this comment for profanity"});
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Question
I am building an AI agent with LangChain and need to add content moderation. How can I filter profanity in user inputs and AI outputs?
Answer
Use glin-profanity with its built-in AI framework integrations:
Option 1: LangChain Tools
Option 2: OpenAI Function Calling
Option 3: Vercel AI SDK
Option 4: MCP Server (for Claude/Cursor)
{ "mcpServers": { "glin-profanity": { "command": "npx", "args": ["-y", "glin-profanity-mcp"] } } }Available Tools
Why use glin-profanity instead of AI moderation?
Links
All reactions