Error Handling GuideError Scenarios
Scenario 1: Content Review Rejection
Handling candidatesTokenCount = 0
Scenario
Content rejected at review stage before generation starts.
Response Example
{
"candidates": [{ "content": { "parts": [] }, "finishReason": "STOP" }],
"usageMetadata": { "candidatesTokenCount": 0 }
}Key Features
- ✅
candidatesTokenCount: 0- Most critical indicator - ⚠️
finishReason: "STOP"- Misleading! - ✅
parts: []- Empty
Detection
function detectContentReviewRejection(data) {
if (data.usageMetadata?.candidatesTokenCount === 0) {
return {
isRejected: true,
stage: 'CONTENT_REVIEW'
};
}
return { isRejected: false };
}User Message
❌ Content Review Failed
Your request was rejected during content review.
Suggestions:
✓ Check prompt for sensitive content
✓ Ensure reference images are appropriate
✓ Use positive, specific descriptionsCommon Triggers
- Sensitive keywords in prompt
- Inappropriate reference images
- Policy violations
Related Docs
How is this guide?