FAILURE MAP
← Case archive

FA-96306 / Postal address normalization / Open access

Address completeness checker: whitespace-only values count as present · case 01

A city consisting of a tab passes the check.

Verified by executionVariant 1 · 12 checks per implementationDownload source bundle ↓JSON ↗

ROOT CAUSE

Values are tested for truthiness without stripping whitespace.

VERIFIED REPAIR

Strip all surrounding whitespace before testing.

Unsuccessful approach: Stripping only spaces still treats a tab as a city.

Case contract

Input a dict. Unknown country (not AA, BB, CC) returns ["country_unknown"]. Values are stripped of all whitespace (None counts as blank). Issues, in order: line1_missing; line2_duplicate when a non-blank line2 equals line1 ignoring case; city_missing; for AA region_missing or region_invalid (not two letters); for AA and BB postal_missing or postal_invalid (AA 5 digits, BB 4 digits); for CC postal_unexpected when a non-blank code is given.

Why this case matters

Completeness checks gate address entry; false positives block valid orders and false negatives let undeliverable addresses through.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    c = x.get('country', '')
    if c not in ('AA', 'BB', 'CC'):
        return ['country_unknown']
    g = lambda k: (x.get(k) or '')
    issues = []
    if not g('line1'):
        issues.append('line1_missing')
    if g('line2') and g('line2').upper() == g('line1').upper():
        issues.append('line2_duplicate')
    if not g('city'):
        issues.append('city_missing')
    if c == 'AA':
        if not g('region'):
            issues.append('region_missing')
        elif not (len(g('region')) == 2 and g('region').isalpha()):
            issues.append('region_invalid')
    if c in ('AA', 'BB'):
        need = 5 if c == 'AA' else 4
        if not g('postal'):
            issues.append('postal_missing')
        elif not (len(g('postal')) == need and g('postal').isdigit()):
            issues.append('postal_invalid')
    elif g('postal'):
        issues.append('postal_unexpected')
    return issues
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['complete domestic address', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '21 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '21 Fake Rd', 'line2': '21 FAKE RD', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '21 Fake Rd', 'city': 'Faketown', 'postal': '1234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '21 Fake Rd', 'city': 'Faketown', 'postal': '1234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'Z9', 'postal': '11345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZZ', 'postal': '11345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '21 Fake Rd', 'city': 'Faketown', 'country': 'CC', 'postal': '9919'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '21 Fake Rd', 'city': 'Faketown', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '22 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '22 Fake Rd', 'line2': '22 FAKE RD', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'postal': '2234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'postal': '2234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'Z9', 'postal': '12345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZZ', 'postal': '12345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'country': 'CC', 'postal': '9929'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '23 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '23 Fake Rd', 'line2': '23 FAKE RD', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'postal': '3234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'postal': '3234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'Z9', 'postal': '13345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZZ', 'postal': '13345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'country': 'CC', 'postal': '9939'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '24 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '24 Fake Rd', 'line2': '24 FAKE RD', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '24 Fake Rd', 'city': 'Quillby', 'postal': '4234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '24 Fake Rd', 'city': 'Quillby', 'postal': '4234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'Z9', 'postal': '14345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZZ', 'postal': '14345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '24 Fake Rd', 'city': 'Quillby', 'country': 'CC', 'postal': '9949'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '24 Fake Rd', 'city': 'Quillby', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '25 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '25 Fake Rd', 'line2': '25 FAKE RD', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'postal': '5234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'postal': '5234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'Z9', 'postal': '15345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZZ', 'postal': '15345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'country': 'CC', 'postal': '9959'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'DD'}, ['country_unknown']]]]
for label, arg, expected in fixtures[N - 1]:
    check(label, solve(arg), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
complete domestic address[][]Passed
tab-only city is missing[]['city_missing']Failed
second line repeats the first in capitals['line2_duplicate']['line2_duplicate']Passed
region not needed for BB[][]Passed
region ignored for BB[][]Passed
region with a digit['region_invalid']['region_invalid']Passed
three-letter region['region_invalid']['region_invalid']Passed
four-digit AA code['postal_invalid']['postal_invalid']Passed
code given where none is used['postal_unexpected']['postal_unexpected']Passed
blank code where none is used[][]Passed
blank required code['postal_missing']['postal_missing']Passed
unknown country['country_unknown']['country_unknown']Passed

SHA-256 / 7c430e7254999152130aec91af5c6bbbc176b2143dd1b5227b1ba534c34a25d7

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    c = x.get('country', '')
    if c not in ('AA', 'BB', 'CC'):
        return ['country_unknown']
    g = lambda k: (x.get(k) or '').strip(' ')
    issues = []
    if not g('line1'):
        issues.append('line1_missing')
    if g('line2') and g('line2').upper() == g('line1').upper():
        issues.append('line2_duplicate')
    if not g('city'):
        issues.append('city_missing')
    if c == 'AA':
        if not g('region'):
            issues.append('region_missing')
        elif not (len(g('region')) == 2 and g('region').isalpha()):
            issues.append('region_invalid')
    if c in ('AA', 'BB'):
        need = 5 if c == 'AA' else 4
        if not g('postal'):
            issues.append('postal_missing')
        elif not (len(g('postal')) == need and g('postal').isdigit()):
            issues.append('postal_invalid')
    elif g('postal'):
        issues.append('postal_unexpected')
    return issues
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['complete domestic address', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '21 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '21 Fake Rd', 'line2': '21 FAKE RD', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '21 Fake Rd', 'city': 'Faketown', 'postal': '1234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '21 Fake Rd', 'city': 'Faketown', 'postal': '1234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'Z9', 'postal': '11345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZZ', 'postal': '11345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '21 Fake Rd', 'city': 'Faketown', 'country': 'CC', 'postal': '9919'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '21 Fake Rd', 'city': 'Faketown', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '22 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '22 Fake Rd', 'line2': '22 FAKE RD', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'postal': '2234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'postal': '2234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'Z9', 'postal': '12345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZZ', 'postal': '12345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'country': 'CC', 'postal': '9929'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '23 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '23 Fake Rd', 'line2': '23 FAKE RD', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'postal': '3234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'postal': '3234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'Z9', 'postal': '13345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZZ', 'postal': '13345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'country': 'CC', 'postal': '9939'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '24 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '24 Fake Rd', 'line2': '24 FAKE RD', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '24 Fake Rd', 'city': 'Quillby', 'postal': '4234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '24 Fake Rd', 'city': 'Quillby', 'postal': '4234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'Z9', 'postal': '14345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZZ', 'postal': '14345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '24 Fake Rd', 'city': 'Quillby', 'country': 'CC', 'postal': '9949'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '24 Fake Rd', 'city': 'Quillby', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '25 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '25 Fake Rd', 'line2': '25 FAKE RD', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'postal': '5234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'postal': '5234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'Z9', 'postal': '15345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZZ', 'postal': '15345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'country': 'CC', 'postal': '9959'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'DD'}, ['country_unknown']]]]
for label, arg, expected in fixtures[N - 1]:
    check(label, solve(arg), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
complete domestic address[][]Passed
tab-only city is missing[]['city_missing']Failed
second line repeats the first in capitals['line2_duplicate']['line2_duplicate']Passed
region not needed for BB[][]Passed
region ignored for BB[][]Passed
region with a digit['region_invalid']['region_invalid']Passed
three-letter region['region_invalid']['region_invalid']Passed
four-digit AA code['postal_invalid']['postal_invalid']Passed
code given where none is used['postal_unexpected']['postal_unexpected']Passed
blank code where none is used[][]Passed
blank required code['postal_missing']['postal_missing']Passed
unknown country['country_unknown']['country_unknown']Passed

SHA-256 / f113684dff222bf35a0b4dcf2b65a6790cbe0b66b320ef6aeb4b82224028e93d

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json

N = 1
observations = []
def solve(x):
    c = x.get('country', '')
    if c not in ('AA', 'BB', 'CC'):
        return ['country_unknown']
    g = lambda k: (x.get(k) or '').strip()
    issues = []
    if not g('line1'):
        issues.append('line1_missing')
    if g('line2') and g('line2').upper() == g('line1').upper():
        issues.append('line2_duplicate')
    if not g('city'):
        issues.append('city_missing')
    if c == 'AA':
        if not g('region'):
            issues.append('region_missing')
        elif not (len(g('region')) == 2 and g('region').isalpha()):
            issues.append('region_invalid')
    if c in ('AA', 'BB'):
        need = 5 if c == 'AA' else 4
        if not g('postal'):
            issues.append('postal_missing')
        elif not (len(g('postal')) == need and g('postal').isdigit()):
            issues.append('postal_invalid')
    elif g('postal'):
        issues.append('postal_unexpected')
    return issues
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['complete domestic address', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '21 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '21 Fake Rd', 'line2': '21 FAKE RD', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '21 Fake Rd', 'city': 'Faketown', 'postal': '1234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '21 Fake Rd', 'city': 'Faketown', 'postal': '1234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'Z9', 'postal': '11345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZZ', 'postal': '11345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '21 Fake Rd', 'city': 'Faketown', 'country': 'CC', 'postal': '9919'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '21 Fake Rd', 'city': 'Faketown', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '21 Fake Rd', 'line2': '', 'city': 'Faketown', 'region': 'ZZ', 'postal': '11345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '22 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '22 Fake Rd', 'line2': '22 FAKE RD', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'postal': '2234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'postal': '2234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'Z9', 'postal': '12345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZZ', 'postal': '12345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'country': 'CC', 'postal': '9929'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '22 Fake Rd', 'city': 'Nowhereville', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '22 Fake Rd', 'line2': '', 'city': 'Nowhereville', 'region': 'ZZ', 'postal': '12345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '23 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '23 Fake Rd', 'line2': '23 FAKE RD', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'postal': '3234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'postal': '3234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'Z9', 'postal': '13345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZZ', 'postal': '13345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'country': 'CC', 'postal': '9939'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '23 Fake Rd', 'city': 'Zorbleton', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '23 Fake Rd', 'line2': '', 'city': 'Zorbleton', 'region': 'ZZ', 'postal': '13345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '24 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '24 Fake Rd', 'line2': '24 FAKE RD', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '24 Fake Rd', 'city': 'Quillby', 'postal': '4234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '24 Fake Rd', 'city': 'Quillby', 'postal': '4234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'Z9', 'postal': '14345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZZ', 'postal': '14345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '24 Fake Rd', 'city': 'Quillby', 'country': 'CC', 'postal': '9949'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '24 Fake Rd', 'city': 'Quillby', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '24 Fake Rd', 'line2': '', 'city': 'Quillby', 'region': 'ZZ', 'postal': '14345', 'country': 'DD'}, ['country_unknown']]], [['complete domestic address', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, []], ['tab-only city is missing', {'line1': '25 Fake Rd', 'line2': '', 'city': '\t', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, ['city_missing']], ['second line repeats the first in capitals', {'line1': '25 Fake Rd', 'line2': '25 FAKE RD', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'AA'}, ['line2_duplicate']], ['region not needed for BB', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'postal': '5234', 'country': 'BB'}, []], ['region ignored for BB', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'postal': '5234', 'country': 'BB', 'region': 'Q1'}, []], ['region with a digit', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'Z9', 'postal': '15345', 'country': 'AA'}, ['region_invalid']], ['three-letter region', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZZ', 'postal': '15345', 'country': 'AA'}, ['region_invalid']], ['four-digit AA code', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '1234', 'country': 'AA'}, ['postal_invalid']], ['code given where none is used', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'country': 'CC', 'postal': '9959'}, ['postal_unexpected']], ['blank code where none is used', {'line1': '25 Fake Rd', 'city': 'Spraxham', 'country': 'CC', 'postal': ''}, []], ['blank required code', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '', 'country': 'AA'}, ['postal_missing']], ['unknown country', {'line1': '25 Fake Rd', 'line2': '', 'city': 'Spraxham', 'region': 'ZZ', 'postal': '15345', 'country': 'DD'}, ['country_unknown']]]]
for label, arg, expected in fixtures[N - 1]:
    check(label, solve(arg), expected)
print(json.dumps({"observations": observations, "passed": all(x["passed"] for x in observations)}, ensure_ascii=False))
raise SystemExit(0 if all(x["passed"] for x in observations) else 1)
Boundary fixtureActualExpectedOutcome
complete domestic address[][]Passed
tab-only city is missing['city_missing']['city_missing']Passed
second line repeats the first in capitals['line2_duplicate']['line2_duplicate']Passed
region not needed for BB[][]Passed
region ignored for BB[][]Passed
region with a digit['region_invalid']['region_invalid']Passed
three-letter region['region_invalid']['region_invalid']Passed
four-digit AA code['postal_invalid']['postal_invalid']Passed
code given where none is used['postal_unexpected']['postal_unexpected']Passed
blank code where none is used[][]Passed
blank required code['postal_missing']['postal_missing']Passed
unknown country['country_unknown']['country_unknown']Passed

SHA-256 / dbc7a59dfcc4b9ccefc400edef9c44e27ea69ba556363ba18b0a3a058249131c

Verification & scope

A deterministic toy contract over synthetic, obviously fictitious addresses. The rules are stipulated for this model only and make no claim of conformance with any postal authority standard. This reproducer isolates one failure mechanism. Results cover the supplied fixtures. Variants within a family share a test contract and should remain grouped when constructing evaluation splits. Related mechanisms with a shared evaluation_group must also remain together; these controlled models are not independent production incidents.

Observations recorded using Python 3.12.14 at 2026-09-29T14:52:21.572910+00:00.

Case digest / 561ad2d272c6e7abe888b4433c7f9036c81319ce8ebac55afc57e66b8313330d