Relevance Checking
Verify that comments stay on-topic and don't violate banned topic rules.
What it checks:
- On-topic detection: Is the comment relevant to the article?
- Banned topics: Does it discuss topics you've prohibited?
Reference
See the Relevance Checking API Reference for method signatures and parameters.
Response: CommentRelevanceResult
By Example
Basic Usage
- Python
- PHP
- REST API
- Blocking Client
- Async Client
result = client.check_relevance(
"This comment discusses the article topic",
article_id
)
print(f"On topic: {result.on_topic.on_topic}")
print(f"Confidence: {result.on_topic.confidence:.2f}")
print(f"Reasoning: {result.on_topic.reasoning}")
# Banned topics info
print(f"Banned topics found: {result.banned_topics.banned_topics}")
print(f"Quantity on banned: {result.banned_topics.quantity_on_banned_topics:.2f}")
result = await client.check_relevance(
"This comment discusses the article topic",
article_id
)
print(f"On topic: {result.on_topic.on_topic}")
print(f"Confidence: {result.on_topic.confidence:.2f}")
print(f"Reasoning: {result.on_topic.reasoning}")
# Banned topics info
print(f"Banned topics found: {result.banned_topics.banned_topics}")
print(f"Quantity on banned: {result.banned_topics.quantity_on_banned_topics:.2f}")
$client->checkRelevance($articleId, "This comment discusses the article topic")
->then(function ($result) {
echo "On topic: " . ($result->onTopic->onTopic ? 'Yes' : 'No') . "\n";
echo "Confidence: " . number_format($result->onTopic->confidence, 2) . "\n";
echo "Reasoning: " . $result->onTopic->reasoning . "\n";
echo "Banned topics: " . implode(', ', $result->bannedTopics->bannedTopics) . "\n";
});
$client->run();
Try it out live →
curl -X POST https://app.respectify.ai/v0.2/commentrelevance \
-H "X-User-Email: your@email.com" \
-H "X-API-Key: your-api-key" \
-d "article_context_id=550e8400-e29b-41d4-a716-446655440000" \
-d "comment=This comment discusses the article topic"
Response:
{
"on_topic": {
"reasoning": "The comment is directly related to the article content.",
"on_topic": true,
"confidence": 0.9
},
"banned_topics": {
"reasoning": "No banned topics detected.",
"banned_topics": [],
"quantity_on_banned_topics": 0,
"confidence": 1.0
}
}
With Banned Topics
Specify topics that shouldn't be discussed:
- Python
- PHP
- REST API
- Blocking Client
- Async Client
result = client.check_relevance(
"Let me tell you about politics...",
article_id,
banned_topics=['politics', 'religion', 'controversial-subject']
)
if result.banned_topics.banned_topics:
print(f"Comment violates banned topics: {result.banned_topics.banned_topics}")
result = await client.check_relevance(
"Let me tell you about politics...",
article_id,
banned_topics=['politics', 'religion', 'controversial-subject']
)
if result.banned_topics.banned_topics:
print(f"Comment violates banned topics: {result.banned_topics.banned_topics}")
$client->checkRelevance(
$articleId,
"Let me tell you about politics...",
['politics', 'religion', 'controversial-subject']
)->then(function ($result) {
if (!empty($result->bannedTopics->bannedTopics)) {
echo "Violates: " . implode(', ', $result->bannedTopics->bannedTopics);
}
});
Try it out live →
curl -X POST https://app.respectify.ai/v0.2/commentrelevance \
-H "X-User-Email: your@email.com" \
-H "X-API-Key: your-api-key" \
-d "article_context_id=550e8400-e29b-41d4-a716-446655440000" \
-d "comment=Let me tell you about politics..." \
-d "banned_topics[]=politics" \
-d "banned_topics[]=religion" \
-d "banned_topics[]=controversial-subject"
Response:
{
"on_topic": {
"reasoning": "The comment veers off-topic from the article's subject matter.",
"on_topic": false,
"confidence": 0.85
},
"banned_topics": {
"reasoning": "Comment discusses politics, which is in the banned topics list.",
"banned_topics": ["politics"],
"quantity_on_banned_topics": 0.8,
"confidence": 0.92
}
}