FAILURE MAP
← Case archive

FA-96706 / Phone number formatting / Open access

Emergency and service code classifier: only the first feature code is removed · case 01

"*67*82 0555..." is invalid instead of a national number with two feature tags.

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

ROOT CAUSE

Feature codes are stripped with a single if.

VERIFIED REPAIR

Strip feature codes repeatedly while they are present.

Unsuccessful approach: Looping but overwriting the tag list keeps only the last feature code.

Case contract

Input [dialed, country] with toy tables AA (emergency 133/144, service = 4 digits starting 1, trunk 0, 9 national digits) and BB (emergency 755, service = 3 digits starting 7, no trunk, 7 national digits). Remove spaces; strip any number of leading "*NN" feature codes into tags. The rest must be digits. Classify in order: exact emergency code, service code, then a national number (trunk required and removed when the country has one). Return tags + [class].

Why this case matters

Emergency and short service codes must be recognized before any national formatting, or emergency calls are rewritten or blocked.

1 / The failure

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

N = 1
observations = []
def solve(x):
    s, country = x
    T = {'AA': {'emergency': ('133', '144'), 'svc': '1', 'svc_len': 4, 'trunk': '0', 'nsn': 9},
         'BB': {'emergency': ('755',), 'svc': '7', 'svc_len': 3, 'trunk': '', 'nsn': 7}}
    c = T[country]
    tags = []
    s = s.replace(' ', '')
    if s.startswith('*') and len(s) >= 3 and s[1:3].isdigit():
        tags.append('feature:' + s[1:3])
        s = s[3:]
    if not s.isdigit():
        return tags + ['invalid']
    if s in c['emergency']:
        return tags + ['emergency']
    if s.startswith(c['svc']) and len(s) == c['svc_len']:
        return tags + ['service']
    if c['trunk'] and s.startswith(c['trunk']):
        s = s[len(c['trunk']):]
    elif c['trunk']:
        return tags + ['invalid']
    return tags + (['national'] if len(s) == c['nsn'] else ['invalid'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1331', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010111', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010111', 'AA'], ['invalid']], ['too short for a service code', ['11', 'AA'], ['invalid']], ['too long for a service code', ['11111', 'AA'], ['invalid']], ['hash inside a number', ['5550#11', 'BB'], ['invalid']], ['BB national number', ['555 0111', 'BB'], ['national']], ['BB service code', ['712', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1332', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010222', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010222', 'AA'], ['invalid']], ['too short for a service code', ['12', 'AA'], ['invalid']], ['too long for a service code', ['12222', 'AA'], ['invalid']], ['hash inside a number', ['5550#12', 'BB'], ['invalid']], ['BB national number', ['555 0122', 'BB'], ['national']], ['BB service code', ['723', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1333', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010333', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010333', 'AA'], ['invalid']], ['too short for a service code', ['13', 'AA'], ['invalid']], ['too long for a service code', ['13333', 'AA'], ['invalid']], ['hash inside a number', ['5550#13', 'BB'], ['invalid']], ['BB national number', ['555 0133', 'BB'], ['national']], ['BB service code', ['734', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1334', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010444', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010444', 'AA'], ['invalid']], ['too short for a service code', ['14', 'AA'], ['invalid']], ['too long for a service code', ['14444', 'AA'], ['invalid']], ['hash inside a number', ['5550#14', 'BB'], ['invalid']], ['BB national number', ['555 0144', 'BB'], ['national']], ['BB service code', ['745', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1335', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010555', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010555', 'AA'], ['invalid']], ['too short for a service code', ['15', 'AA'], ['invalid']], ['too long for a service code', ['15555', 'AA'], ['invalid']], ['hash inside a number', ['5550#15', 'BB'], ['invalid']], ['BB national number', ['555 0155', 'BB'], ['national']], ['BB service code', ['756', 'BB'], ['service']]]]
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
emergency code['emergency']['emergency']Passed
emergency code inside the service range['emergency']['emergency']Passed
feature code before emergency code['feature:67', 'emergency']['feature:67', 'emergency']Passed
service code sharing the emergency prefix['service']['service']Passed
trunk before an emergency code['invalid']['invalid']Passed
two feature codes['feature:67', 'invalid']['feature:67', 'feature:82', 'national']Failed
national number without trunk['invalid']['invalid']Passed
too short for a service code['invalid']['invalid']Passed
too long for a service code['invalid']['invalid']Passed
hash inside a number['invalid']['invalid']Passed
BB national number['national']['national']Passed
BB service code['service']['service']Passed

SHA-256 / 25a85ded152123cf194b3470d8809e8449416e75d6983e6b539208a18d68bc52

2 / The unsuccessful fix

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

N = 1
observations = []
def solve(x):
    s, country = x
    T = {'AA': {'emergency': ('133', '144'), 'svc': '1', 'svc_len': 4, 'trunk': '0', 'nsn': 9},
         'BB': {'emergency': ('755',), 'svc': '7', 'svc_len': 3, 'trunk': '', 'nsn': 7}}
    c = T[country]
    tags = []
    s = s.replace(' ', '')
    while s.startswith('*') and len(s) >= 3 and s[1:3].isdigit():
        tags = ['feature:' + s[1:3]]
        s = s[3:]
    if not s.isdigit():
        return tags + ['invalid']
    if s in c['emergency']:
        return tags + ['emergency']
    if s.startswith(c['svc']) and len(s) == c['svc_len']:
        return tags + ['service']
    if c['trunk'] and s.startswith(c['trunk']):
        s = s[len(c['trunk']):]
    elif c['trunk']:
        return tags + ['invalid']
    return tags + (['national'] if len(s) == c['nsn'] else ['invalid'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1331', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010111', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010111', 'AA'], ['invalid']], ['too short for a service code', ['11', 'AA'], ['invalid']], ['too long for a service code', ['11111', 'AA'], ['invalid']], ['hash inside a number', ['5550#11', 'BB'], ['invalid']], ['BB national number', ['555 0111', 'BB'], ['national']], ['BB service code', ['712', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1332', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010222', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010222', 'AA'], ['invalid']], ['too short for a service code', ['12', 'AA'], ['invalid']], ['too long for a service code', ['12222', 'AA'], ['invalid']], ['hash inside a number', ['5550#12', 'BB'], ['invalid']], ['BB national number', ['555 0122', 'BB'], ['national']], ['BB service code', ['723', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1333', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010333', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010333', 'AA'], ['invalid']], ['too short for a service code', ['13', 'AA'], ['invalid']], ['too long for a service code', ['13333', 'AA'], ['invalid']], ['hash inside a number', ['5550#13', 'BB'], ['invalid']], ['BB national number', ['555 0133', 'BB'], ['national']], ['BB service code', ['734', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1334', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010444', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010444', 'AA'], ['invalid']], ['too short for a service code', ['14', 'AA'], ['invalid']], ['too long for a service code', ['14444', 'AA'], ['invalid']], ['hash inside a number', ['5550#14', 'BB'], ['invalid']], ['BB national number', ['555 0144', 'BB'], ['national']], ['BB service code', ['745', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1335', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010555', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010555', 'AA'], ['invalid']], ['too short for a service code', ['15', 'AA'], ['invalid']], ['too long for a service code', ['15555', 'AA'], ['invalid']], ['hash inside a number', ['5550#15', 'BB'], ['invalid']], ['BB national number', ['555 0155', 'BB'], ['national']], ['BB service code', ['756', 'BB'], ['service']]]]
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
emergency code['emergency']['emergency']Passed
emergency code inside the service range['emergency']['emergency']Passed
feature code before emergency code['feature:67', 'emergency']['feature:67', 'emergency']Passed
service code sharing the emergency prefix['service']['service']Passed
trunk before an emergency code['invalid']['invalid']Passed
two feature codes['feature:82', 'national']['feature:67', 'feature:82', 'national']Failed
national number without trunk['invalid']['invalid']Passed
too short for a service code['invalid']['invalid']Passed
too long for a service code['invalid']['invalid']Passed
hash inside a number['invalid']['invalid']Passed
BB national number['national']['national']Passed
BB service code['service']['service']Passed

SHA-256 / f811b30af697185f6bdd4061f0e41c6e05c5950d3cc54d41f2d6ea33df5b31f2

3 / The verified repair

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

N = 1
observations = []
def solve(x):
    s, country = x
    T = {'AA': {'emergency': ('133', '144'), 'svc': '1', 'svc_len': 4, 'trunk': '0', 'nsn': 9},
         'BB': {'emergency': ('755',), 'svc': '7', 'svc_len': 3, 'trunk': '', 'nsn': 7}}
    c = T[country]
    tags = []
    s = s.replace(' ', '')
    while s.startswith('*') and len(s) >= 3 and s[1:3].isdigit():
        tags.append('feature:' + s[1:3])
        s = s[3:]
    if not s.isdigit():
        return tags + ['invalid']
    if s in c['emergency']:
        return tags + ['emergency']
    if s.startswith(c['svc']) and len(s) == c['svc_len']:
        return tags + ['service']
    if c['trunk'] and s.startswith(c['trunk']):
        s = s[len(c['trunk']):]
    elif c['trunk']:
        return tags + ['invalid']
    return tags + (['national'] if len(s) == c['nsn'] else ['invalid'])
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1331', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010111', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010111', 'AA'], ['invalid']], ['too short for a service code', ['11', 'AA'], ['invalid']], ['too long for a service code', ['11111', 'AA'], ['invalid']], ['hash inside a number', ['5550#11', 'BB'], ['invalid']], ['BB national number', ['555 0111', 'BB'], ['national']], ['BB service code', ['712', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1332', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010222', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010222', 'AA'], ['invalid']], ['too short for a service code', ['12', 'AA'], ['invalid']], ['too long for a service code', ['12222', 'AA'], ['invalid']], ['hash inside a number', ['5550#12', 'BB'], ['invalid']], ['BB national number', ['555 0122', 'BB'], ['national']], ['BB service code', ['723', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1333', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010333', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010333', 'AA'], ['invalid']], ['too short for a service code', ['13', 'AA'], ['invalid']], ['too long for a service code', ['13333', 'AA'], ['invalid']], ['hash inside a number', ['5550#13', 'BB'], ['invalid']], ['BB national number', ['555 0133', 'BB'], ['national']], ['BB service code', ['734', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1334', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010444', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010444', 'AA'], ['invalid']], ['too short for a service code', ['14', 'AA'], ['invalid']], ['too long for a service code', ['14444', 'AA'], ['invalid']], ['hash inside a number', ['5550#14', 'BB'], ['invalid']], ['BB national number', ['555 0144', 'BB'], ['national']], ['BB service code', ['745', 'BB'], ['service']]], [['emergency code', ['133', 'AA'], ['emergency']], ['emergency code inside the service range', ['755', 'BB'], ['emergency']], ['feature code before emergency code', ['*67 755', 'BB'], ['feature:67', 'emergency']], ['service code sharing the emergency prefix', ['1335', 'AA'], ['service']], ['trunk before an emergency code', ['0133', 'AA'], ['invalid']], ['two feature codes', ['*67*82 0555010555', 'AA'], ['feature:67', 'feature:82', 'national']], ['national number without trunk', ['555010555', 'AA'], ['invalid']], ['too short for a service code', ['15', 'AA'], ['invalid']], ['too long for a service code', ['15555', 'AA'], ['invalid']], ['hash inside a number', ['5550#15', 'BB'], ['invalid']], ['BB national number', ['555 0155', 'BB'], ['national']], ['BB service code', ['756', 'BB'], ['service']]]]
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
emergency code['emergency']['emergency']Passed
emergency code inside the service range['emergency']['emergency']Passed
feature code before emergency code['feature:67', 'emergency']['feature:67', 'emergency']Passed
service code sharing the emergency prefix['service']['service']Passed
trunk before an emergency code['invalid']['invalid']Passed
two feature codes['feature:67', 'feature:82', 'national']['feature:67', 'feature:82', 'national']Passed
national number without trunk['invalid']['invalid']Passed
too short for a service code['invalid']['invalid']Passed
too long for a service code['invalid']['invalid']Passed
hash inside a number['invalid']['invalid']Passed
BB national number['national']['national']Passed
BB service code['service']['service']Passed

SHA-256 / 807948ca28bf9604562aed971c70d73e84e5f10dc502023c7755264cfb61d3b6

Verification & scope

A deterministic toy contract over synthetic, obviously fictitious telephone numbers and toy country tables. The rules are stipulated for this model only and make no claim of conformance with any numbering plan or telecommunications 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:25.145941+00:00.

Case digest / 114d7682a39071e5b5063bdf03508536f322425a08f9f84f667727ecbda68a54