Not every CAPTCHA solution has the same confidence level. A clear, well-contrasted image produces a high-confidence answer. A noisy, distorted image might yield a best-guess answer. Understanding and using quality indicators helps you decide whether to trust a solution or request a fresh solve.
How Confidence Works
When CaptchaAI solves an image CAPTCHA, the recognition process produces internal confidence metrics. These indicate how certain the system is about each character and the overall answer.
Response Quality Indicators
CaptchaAI provides solution feedback through several mechanisms:
| Indicator | What it tells you |
|---|---|
| Solve speed | Fast solves often indicate clear, easy CAPTCHAs |
| Answer length | Unexpected length may signal recognition issues |
| Character patterns | Mixed case/numbers matching the expected format |
| Report feedback | Reporting incorrect answers improves future accuracy |
Implementing Confidence-Based Logic
Basic Validation
Before using a solution, validate that it matches expected patterns:
import re
def validate_captcha_answer(answer, expected_length=None, expected_pattern=None):
"""Validate a CAPTCHA answer against expected criteria."""
issues = []
if not answer or len(answer.strip()) == 0:
return False, ["Empty answer"]
# Length check
if expected_length and len(answer) != expected_length:
issues.append(f"Expected {expected_length} chars, got {len(answer)}")
# Pattern check (e.g., alphanumeric only)
if expected_pattern and not re.match(expected_pattern, answer):
issues.append(f"Doesn't match pattern {expected_pattern}")
# Common OCR confusion check
suspicious_chars = check_confusable_chars(answer)
if suspicious_chars:
issues.append(f"Possible OCR confusion: {suspicious_chars}")
return len(issues) == 0, issues
def check_confusable_chars(answer):
"""Flag characters that are commonly confused in OCR."""
confusables = {
"O/0": any(c in answer for c in "O0"),
"l/1/I": sum(1 for c in answer if c in "l1I") > 1,
"S/5": any(c in answer for c in "S5"),
"B/8": any(c in answer for c in "B8"),
}
flagged = [k for k, v in confusables.items() if v]
return flagged if flagged else None
Smart Retry Logic
Retry with fresh solves when confidence is low:
import requests
import time
def solve_with_confidence(image_base64, max_attempts=3,
expected_length=None, expected_pattern=None):
"""Solve an image CAPTCHA with confidence-based retry."""
for attempt in range(max_attempts):
# Submit to CaptchaAI
resp = requests.post("https://ocr.captchaai.com/in.php", data={
"key": "YOUR_API_KEY",
"method": "base64",
"body": image_base64,
"json": 1
})
task_id = resp.json()["request"]
# Poll for result
answer = poll_result(task_id)
if not answer:
continue
# Validate
is_valid, issues = validate_captcha_answer(
answer, expected_length, expected_pattern
)
if is_valid:
return answer
print(f"Attempt {attempt + 1}: Answer '{answer}' — issues: {issues}")
# Report incorrect if we know it's wrong
if expected_length and len(answer) != expected_length:
report_incorrect(task_id)
return answer # Return best attempt even if validation fails
def poll_result(task_id):
for _ in range(30):
time.sleep(3)
result = requests.get("https://ocr.captchaai.com/res.php", params={
"key": "YOUR_API_KEY",
"action": "get",
"id": task_id,
"json": 1
})
data = result.json()
if data["status"] == 1:
return data["request"]
return None
def report_incorrect(task_id):
"""Report that a solution was incorrect."""
requests.get("https://ocr.captchaai.com/res.php", params={
"key": "YOUR_API_KEY",
"action": "reportbad",
"id": task_id
})
JavaScript Implementation
async function solveWithConfidence(imageBase64, options = {}) {
const {
maxAttempts = 3,
expectedLength = null,
expectedPattern = null
} = options;
for (let attempt = 0; attempt < maxAttempts; attempt++) {
const answer = await solveCaptcha(imageBase64);
if (!answer) continue;
const validation = validateAnswer(answer, expectedLength, expectedPattern);
if (validation.isValid) {
return { answer, confidence: 'high', attempt: attempt + 1 };
}
console.log(`Attempt ${attempt + 1}: "${answer}" — ${validation.issues.join(', ')}`);
}
// Return last answer with low confidence
return { answer: null, confidence: 'low', attempt: maxAttempts };
}
function validateAnswer(answer, expectedLength, expectedPattern) {
const issues = [];
if (expectedLength && answer.length !== expectedLength) {
issues.push(`Wrong length: ${answer.length} vs expected ${expectedLength}`);
}
if (expectedPattern && !new RegExp(expectedPattern).test(answer)) {
issues.push(`Pattern mismatch`);
}
return { isValid: issues.length === 0, issues };
}
Reporting Incorrect Solutions
CaptchaAI allows reporting incorrect solutions, which helps improve accuracy and may provide credit:
# Report an incorrect solution
requests.get("https://ocr.captchaai.com/res.php", params={
"key": "YOUR_API_KEY",
"action": "reportbad",
"id": task_id
})
Only report genuinely incorrect answers — not solutions that were correct but rejected due to token expiration or other issues.
Tracking Solve Rates
Monitor your solve accuracy over time:
class SolveTracker:
def __init__(self):
self.total = 0
self.accepted = 0
self.rejected = 0
def record(self, accepted):
self.total += 1
if accepted:
self.accepted += 1
else:
self.rejected += 1
@property
def success_rate(self):
if self.total == 0:
return 0
return self.accepted / self.total
def report(self):
rate = self.success_rate * 100
print(f"Total: {self.total}, Accepted: {self.accepted}, "
f"Rejected: {self.rejected}, Rate: {rate:.1f}%")
# Usage
tracker = SolveTracker()
answer = solve_captcha(image)
result = submit_form(answer)
tracker.record(result.success)
tracker.report()
# Total: 100, Accepted: 94, Rejected: 6, Rate: 94.0%
Optimizing for Different CAPTCHA Types
| CAPTCHA type | Expected format | Validation approach |
|---|---|---|
| Alphanumeric (4-6 chars) | ^[A-Za-z0-9]{4,6}$ |
Length + pattern check |
| Numbers only | ^[0-9]{4,8}$ |
Digits only validation |
| Math expression | ^\d+$ (result) |
Verify arithmetic is reasonable |
| Case-sensitive | Matches site requirements | Check case mixing |
| Chinese characters | Unicode range | Verify CJK character range |
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| Consistent wrong answers | Poor image quality | Preprocess image before submission |
| Random character substitutions | OCR confusion (O/0, l/1) | Both variants may be valid — try both |
| Answer length varies | CAPTCHA has variable-length text | Don't filter by fixed length |
| High solve time, poor quality | Complex/noisy image | Preprocess or use instructions parameter |
FAQ
Does CaptchaAI return a confidence score with every solution?
CaptchaAI focuses on returning the correct answer. You can implement your own confidence assessment by validating the answer format and tracking acceptance rates.
Should I always retry low-confidence answers?
If you know the expected format (length, character set), retry when the answer doesn't match. But if the format is unknown, using the first answer is usually the best approach.
How does reporting bad solutions help?
Reporting helps CaptchaAI improve its recognition models. It also ensures you aren't charged for genuinely incorrect solutions.
Related Articles
Next Steps
Get reliable image CAPTCHA solutions — sign up for CaptchaAI and implement confidence-based handling.
Discussions (0)
Join the conversation
Sign in to share your opinion.
Sign InNo comments yet.