Debugging False Approvals in a Risk Scoring System
BehavioralModel answerLast updated
Investigate why a return-eligibility scoring service incorrectly approves high-risk requests and identify root causes across inputs, logic, and control flow.
You maintain a risk-scoring service for an e-commerce platform that evaluates return requests. The service computes a risk score from multiple signals:
- Customer's historical return count
- Item value
- Account age
- Product category
- Fraud and abuse indicators
Requests with scores above a threshold are rejected. However, you've recently observed that some high-risk returns are being incorrectly approved, leading to fraud losses.
Your task: Explain your debugging approach and identify six distinct categories of bugs that could cause these false approvals. For each category:
- Describe what could go wrong
- Explain how you would detect it
- Propose how to fix it
- Suggest how to prevent recurrence
Focus on systematic root-cause analysis rather than guessing. Consider the full pipeline: data collection, feature computation, scoring logic, and decision-making.
Hints
Hint 1
Think about the entire decision pipeline: where do inputs come from, how are they transformed, and where is the final decision made?
Hint 2
Replaying past decisions with logged data can isolate whether bugs are in runtime behavior or in the scoring logic itself
Hint 3
Consider what happens when services fail, data is missing, or edge cases like new categories appear
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
Systematic Debugging Approach
The core principle: a false approval means a high-risk request received a "returnable" decision. This can only occur through a limited set of failure modes in the decision pipeline.
Investigation Framework
Step 1: Gather evidence
- Collect confirmed false approvals from fraud reports, chargebacks, or manual reviews
- Pull matching correct rejections as a control group
- Segment by timestamp, product category, customer segment, deployment version, and geographic region
- Look for patterns: did failures start at a specific time (pointing to a code or config change)? Are they concentrated in one category (pointing to a mapping bug)?
Step 2: Reproduce the decision
- Replay each problematic request offline using logged inputs
- Instrument the replay to show each feature's contribution to the final score
- If replay correctly rejects the request, the bug is in data fetching or runtime behavior (timeouts, staleness, race conditions)
- If replay also approves it, the bug is in scoring logic or threshold configuration
Step 3: Isolate the change
- Diff code, configuration, and feature flags around the onset date
- Bisect deployments to find the introducing change
- Compare feature value distributions before and after the issue appeared
Step 4: Use tooling wisely
- Write automated replay scripts to test hypotheses quickly
- Build property tests that must hold (e.g., increasing return count should never decrease risk)
- Validate every hypothesis against real data before implementing fixes
Six Categories of Defects
1. Threshold and Comparison Logic Errors
What goes wrong:
- Incorrect comparison operator (
>instead of>=, or inverted logic) - Score scale mismatch: threshold expects 0-100 but new scoring produces 0-1, so a score of 0.85 passes a threshold of 70
- Threshold applied to the wrong metric
Detection:
- Replay shows high scores still approved
- Unit tests at boundary values reveal the bug
- Distribution analysis shows approved scores clustering above what should be the cutoff
Fix:
- Maintain a single canonical score range with explicit bounds checking
- Use named constants for thresholds with documented units
- Write the comparison once in a tested helper function
Prevention:
- Boundary tests at threshold−ε, threshold, and threshold+ε
- Schema validation on score ranges at startup
- Alert on sudden shifts in approval rate or score distributions
2. Fail-Open Behavior on Errors
What goes wrong:
- Dependency timeouts return default values (e.g., fraud service times out, code assumes "no fraud signals")
- Missing data treated as safe (null return history interpreted as zero returns)
- Exception handlers that default to approval to "avoid blocking customers"
Detection:
- Correlate false approvals with dependency latency spikes or error rates
- Count decisions made with degraded or default data
- Review exception logs during the affected time window
Fix:
- Fail closed: missing critical signals should trigger rejection or manual review
- Distinguish "unknown" (None/null) from "safe" (explicit zero)
- Make degraded-mode behavior an explicit, reviewed policy decision
Prevention:
- Emit metrics for decisions made with incomplete data
- Chaos testing: inject dependency failures and verify safe behavior
- Circuit breakers that route to manual review when data quality degrades
3. Unit and Type Mismatches
What goes wrong:
- Currency units inconsistent (cents vs. dollars, unconverted foreign currency)
- Time units mixed (seconds vs. days for account age)
- Numeric strings compared lexicographically ("9" > "10" evaluates to true)
- Percentage values used as decimals or vice versa
Detection:
- Feature distributions show impossible or suspicious values (average item value of $0.35)
- Compare value ranges before and after the onset
- Type errors or truncation in logs
Fix:
- Normalize at system boundaries into strongly-typed fields with explicit units (
value_usd: Decimal,account_age_days: int) - Validate ranges on ingestion (reject negative prices, ages > 100 years)
- Unit-test conversions explicitly
Prevention:
- Schema contracts between services with unit annotations
- Field naming conventions that include units (
price_cents,duration_seconds) - Automated range assertions on every input
4. Scoring Formula Bugs
What goes wrong:
- Sign errors: account age should increase risk for new users but the coefficient is positive (lowering risk)
- Integer division truncating contributions to zero
- Refactoring accidentally drops a term
- Weights no longer sum correctly after adding new features
- Clipping or saturation applied too aggressively, flattening important signals
Detection:
- Per-feature contribution logging reveals zero or inverted impacts
- Property tests: monotonicity checks fail (increasing returns shouldn't decrease score)
- Manual inspection of feature weights in recent commits
Fix:
- Correct the formula and anchor it with golden test cases from labeled historical data
- Version scoring formulas explicitly and document expected behavior
Prevention:
- Monotonicity property tests for key features
- Shadow-score new formulas in production before cutover, comparing decisions
- Code review checklist specifically for weight and sign correctness
5. Data Staleness and Concurrency Issues
What goes wrong:
- Return counts cached daily, so rapid repeat returns go undetected
- Pending or in-transit returns not included in the count
- Race condition: two concurrent requests both read count=2, both approve, then count becomes 4
- Time-window bugs from timezone handling or clock skew
- Duplicate or linked accounts not merged
Detection:
- Ground-truth reconciliation: compare counts used at decision time with actual database state
- Temporal clustering: multiple approvals from the same customer within minutes
- Cache hit rates and freshness metrics
Fix:
- Read velocity-sensitive signals from strongly consistent storage
- Include pending/processing returns in counts
- Use atomic compare-and-increment or per-customer locks for high-velocity signals
- Implement account-linking to aggregate behavior across related accounts
Prevention:
- Data freshness SLAs with automated alerts
- Concurrency stress tests
- Log data timestamps and versions used for each decision
6. Rule Precedence and Mapping Errors
What goes wrong:
- Category lookup fails on whitespace or case differences, defaulting to low-risk
- New categories missing from mapping tables, assigned safe defaults
- Override rules (VIP status, customer service allowlist) checked before scoring and short-circuit rejection logic
- Feature flags accidentally disable fraud checks in production
- Configuration rollback restores outdated rules
Detection:
- Segment failures by product category, customer tier, or override path
- Audit recent configuration and feature-flag changes
- Look for unknown category warnings in logs
Fix:
- Canonicalize keys (trim, lowercase) before lookup
- Send unknown categories to high-risk default and trigger alerts
- Enforce rule precedence: hard fraud signals override any allowlist
- Configuration changes require approval and testing
Prevention:
- Exhaustiveness checks when schema evolves (new categories must be explicitly mapped)
- Rules precedence table documented and tested
- Canary deployments for configuration changes
- Require paired tests with every rule change
Why This Framework Works
These six categories map cleanly to four pipeline stages:
- Data collection (defects 3, 5): inputs have wrong units, are stale, or are incomplete
- Feature computation (defect 4): the scoring formula itself is broken
- Decision logic (defect 1): the threshold comparison is wrong
- Control flow (defects 2, 6): errors or overrides bypass scoring
Systematically checking each stage ensures comprehensive coverage. Replay-based debugging isolates the stage where things break. Property tests and monitoring prevent regression.
Common Mistakes to Avoid
- Guessing without data: Always reproduce the failure before proposing fixes
- Fixing symptoms: Adjusting the threshold to compensate for a broken formula just hides the root cause
- Trusting AI-generated fixes blindly: Verify every hypothesis against production data
- Deploying without regression tests: The fix must include a test that fails before the patch and passes after