How to Build a Community Forum with AI Moderation
Create a community forum with AI-powered moderation and answer suggestions.
Jay Banlasan
The AI Systems Guy
A community forum with ai moderation and customer support features lets your customers help each other while AI keeps the quality high. I build these for products with active user communities. The AI moderates posts, suggests answers from your knowledge base, and flags unanswered questions for your team.
Community forums scale support in a way that hiring agents cannot. Every answer helps future customers with the same question.
What You Need Before Starting
- A forum platform or custom build (Discourse, or custom with Flask)
- Python 3.8+ with the Anthropic SDK
- A knowledge base for answer suggestions
- Moderation rules and community guidelines
Step 1: Build the Moderation Layer
Screen every post before it goes live:
import anthropic
import json
client = anthropic.Anthropic()
GUIDELINES = """Community rules:
1. No spam or self-promotion
2. No personal attacks or harassment
3. No sharing of private information
4. Stay on topic
5. No asking for or sharing account credentials"""
def moderate_post(post_content, post_title=""):
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=100,
messages=[{
"role": "user",
"content": f"""Review this forum post against community guidelines.
Guidelines: {GUIDELINES}
Title: {post_title}
Content: {post_content}
Respond with JSON: {{"approved": true/false, "reason": "...", "severity": "none/warning/block"}}"""
}]
)
return json.loads(response.content[0].text)
Step 2: Auto-Suggest Answers
When someone posts a question, check if it is already answered:
def suggest_existing_answers(question_text):
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")
query_embedding = model.encode(question_text).tolist()
# Search existing forum posts
forum_results = search_forum_posts(query_embedding, top_k=3)
# Search knowledge base
kb_results = search_knowledge_base(query_embedding, top_k=2)
suggestions = []
for result in forum_results + kb_results:
if result["relevance"] > 0.7:
suggestions.append(result)
return suggestions
Step 3: Handle New Posts
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/api/forum/post", methods=["POST"])
def create_post():
data = request.json
moderation = moderate_post(data["content"], data.get("title", ""))
if not moderation["approved"]:
return jsonify({
"status": "rejected",
"reason": moderation["reason"]
}), 400
suggestions = suggest_existing_answers(data["content"])
if suggestions:
return jsonify({
"status": "suggestions",
"message": "We found some existing answers that might help:",
"suggestions": suggestions
})
post_id = save_post(data)
return jsonify({"status": "published", "post_id": post_id})
Step 4: Flag Unanswered Questions
def check_unanswered_posts():
conn = sqlite3.connect("forum.db")
unanswered = conn.execute("""
SELECT id, title, content, created_at FROM posts
WHERE reply_count = 0
AND created_at < datetime('now', '-4 hours')
AND flagged_for_team = 0
""").fetchall()
for post in unanswered:
conn.execute(
"UPDATE posts SET flagged_for_team = 1 WHERE id = ?",
(post[0],)
)
notify_support_team(post)
conn.commit()
return len(unanswered)
Step 5: Track Community Health
def get_community_metrics(days=30):
conn = sqlite3.connect("forum.db")
start = f"-{days} days"
return {
"new_posts": conn.execute("SELECT COUNT(*) FROM posts WHERE created_at > datetime('now', ?)", (start,)).fetchone()[0],
"replies": conn.execute("SELECT COUNT(*) FROM replies WHERE created_at > datetime('now', ?)", (start,)).fetchone()[0],
"unanswered": conn.execute("SELECT COUNT(*) FROM posts WHERE reply_count = 0 AND created_at > datetime('now', ?)", (start,)).fetchone()[0],
"moderation_blocks": conn.execute("SELECT COUNT(*) FROM moderation_log WHERE action = 'block' AND created_at > datetime('now', ?)", (start,)).fetchone()[0],
"avg_response_hours": conn.execute("""
SELECT AVG((julianday(first_reply_at) - julianday(created_at)) * 24)
FROM posts WHERE first_reply_at IS NOT NULL AND created_at > datetime('now', ?)
""", (start,)).fetchone()[0]
}
What to Build Next
Add reputation scoring for community members. Active, helpful members get highlighted and their answers rank higher. This incentivizes quality contributions and reduces moderation load.
Related Reading
- AI in Customer Service - community forums as a support channel
- The Feedback Loop That Powers Everything - community discussions feeding back into product
- The One Person Company Is Here - community-powered support at scale
Want this system built for your business?
Get a free assessment. We will map every system your business needs and show you the ROI.
Get Your Free Assessment