FAILURE MAP
← Case archive

FA-96911 / Recipe scaling and nutrition / Open access

Volume-to-mass ingredient converter: ingredient name normalization · case 01

"Flour" is rejected as an unknown ingredient.

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

ROOT CAUSE

The lookup key is trimmed but not lower-cased, so capitalized names miss the density table.

VERIFIED REPAIR

Trim and lower-case the ingredient name before lookup.

Unsuccessful approach: Lower-casing without trimming still rejects names with surrounding spaces.

Case contract

Convert amount (fraction string) of cup/tbsp/tsp/ml to grams. 1 cup = 16 tbsp = 48 tsp = 236.5 ml. Grams per cup: flour 120, sugar 200, brown sugar 145 (213 when prefixed "packed "), butter 227, honey 340, water 236. Names are trimmed and case-insensitive; a ", sifted" suffix multiplies density by 9/10. Results below 10 g print one decimal ("%.1f g"), otherwise whole grams, both half-up. Unknown ingredient or unit returns an error string.

Why this case matters

Recipe apps convert American volume measures to weights for scaling and nutrition lookup.

1 / The failure

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(amount, unit, ingredient):
    DENS = {'flour': 120, 'sugar': 200, 'brown sugar': 145, 'butter': 227, 'honey': 340, 'water': 236}
    PER_CUP = {'cup': 1, 'tbsp': 16, 'tsp': 48}
    name = ingredient.strip()
    packed = name.startswith('packed ')
    if packed:
        name = name[len('packed '):]
    sifted = name.endswith(', sifted')
    if sifted:
        name = name[:-len(', sifted')]
    if name not in DENS:
        return 'error: unknown ingredient'
    if unit == 'ml':
        cups = Fraction(amount) / Fraction(2365, 10)
    elif unit in PER_CUP:
        cups = Fraction(amount) / PER_CUP[unit]
    else:
        return 'error: unknown unit'
    d = Fraction(DENS[name])
    if packed and name == 'brown sugar':
        d = Fraction(213)
    if sifted:
        d = d * Fraction(9, 10)
    g = cups * d
    if g < 10:
        return '%.1f g' % (math.floor(g * 10 + Fraction(1, 2)) / 10)
    return '%d g' % math.floor(g + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['one cup flour', ['1', 'cup', 'flour'], '120 g'], ['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
  ['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['regression: ingredient name normalization', ['6', 'ml', '  Honey '], '8.6 g'],
  ['repair check: ingredient name normalization', ['120', 'ml', '  Sugar, Sifted '], '91 g'],
  ['generated control 1', ['1/4', 'ml', 'sugar'], '0.2 g'],
  ['generated control 2', ['4', 'cup', 'water, sifted'], '850 g'],
  ['generated control 3', ['250', 'pinch', 'brown sugar'], 'error: unknown unit']],
 [['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
  ['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['regression: ingredient name normalization', ['1/4', 'ml', '  Flour, Sifted '], '0.1 g'],
  ['repair check: ingredient name normalization', ['5', 'ml', '  Butter, Sifted '], '4.3 g'],
  ['generated control 1', ['6', 'ml', 'saffron'], 'error: unknown ingredient'],
  ['generated control 2', ['1/2', 'cup', 'butter, sifted'], '102 g'],
  ['generated control 3', ['1/3', 'tbsp', 'butter, sifted'], '4.3 g']],
 [['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['regression: ingredient name normalization', ['100', 'ml', '  Brown Sugar '], '61 g'],
  ['repair check: ingredient name normalization', ['5', 'tbsp', '  Sugar '], '63 g'],
  ['generated control 1', ['3', 'tbsp', 'butter, sifted'], '38 g'],
  ['generated control 2', ['120', 'cup', 'PACKED SUGAR'], '24000 g'],
  ['generated control 3', ['120', 'tsp', '  Packed Honey '], '850 g']],
 [['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
  ['regression: ingredient name normalization', ['2', 'tbsp', '  Water '], '30 g'],
  ['repair check: ingredient name normalization', ['15', 'ml', '  Packed Flour '], '7.6 g'],
  ['generated control 1', ['6', 'cup', 'butter'], '1362 g'],
  ['generated control 2', ['4', 'ml', 'water'], '4.0 g'],
  ['generated control 3', ['1/2', 'ml', 'saffron'], 'error: unknown ingredient']],
 [['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
  ['one cup flour', ['1', 'cup', 'flour'], '120 g'],
  ['regression: ingredient name normalization', ['4', 'ml', 'WATER'], '4.0 g'],
  ['repair check: ingredient name normalization', ['4', 'tsp', '  Honey, Sifted '], '26 g'],
  ['generated control 1', ['2', 'ml', 'flour, sifted'], '0.9 g'],
  ['generated control 2', ['3', 'cup', 'honey'], '1020 g'],
  ['generated control 3', ['1/4', 'tsp', 'HONEY'], '1.8 g']]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), 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
one cup flour120 g120 gPassed
exactly ten grams10 g10 gPassed
packed brown sugar213 g213 gPassed
regression: ingredient name normalizationerror: unknown ingredient8.6 gFailed
repair check: ingredient name normalizationerror: unknown ingredient91 gFailed
generated control 10.2 g0.2 gPassed
generated control 2850 g850 gPassed
generated control 3error: unknown uniterror: unknown unitPassed

SHA-256 / 3bfd77b386fa330f50540f2200819cd9632857f5b0bf0281eab16c959b65babe

2 / The unsuccessful fix

Exit 1
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(amount, unit, ingredient):
    DENS = {'flour': 120, 'sugar': 200, 'brown sugar': 145, 'butter': 227, 'honey': 340, 'water': 236}
    PER_CUP = {'cup': 1, 'tbsp': 16, 'tsp': 48}
    name = ingredient.lower()
    packed = name.startswith('packed ')
    if packed:
        name = name[len('packed '):]
    sifted = name.endswith(', sifted')
    if sifted:
        name = name[:-len(', sifted')]
    if name not in DENS:
        return 'error: unknown ingredient'
    if unit == 'ml':
        cups = Fraction(amount) / Fraction(2365, 10)
    elif unit in PER_CUP:
        cups = Fraction(amount) / PER_CUP[unit]
    else:
        return 'error: unknown unit'
    d = Fraction(DENS[name])
    if packed and name == 'brown sugar':
        d = Fraction(213)
    if sifted:
        d = d * Fraction(9, 10)
    g = cups * d
    if g < 10:
        return '%.1f g' % (math.floor(g * 10 + Fraction(1, 2)) / 10)
    return '%d g' % math.floor(g + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['one cup flour', ['1', 'cup', 'flour'], '120 g'], ['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
  ['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['regression: ingredient name normalization', ['6', 'ml', '  Honey '], '8.6 g'],
  ['repair check: ingredient name normalization', ['120', 'ml', '  Sugar, Sifted '], '91 g'],
  ['generated control 1', ['1/4', 'ml', 'sugar'], '0.2 g'],
  ['generated control 2', ['4', 'cup', 'water, sifted'], '850 g'],
  ['generated control 3', ['250', 'pinch', 'brown sugar'], 'error: unknown unit']],
 [['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
  ['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['regression: ingredient name normalization', ['1/4', 'ml', '  Flour, Sifted '], '0.1 g'],
  ['repair check: ingredient name normalization', ['5', 'ml', '  Butter, Sifted '], '4.3 g'],
  ['generated control 1', ['6', 'ml', 'saffron'], 'error: unknown ingredient'],
  ['generated control 2', ['1/2', 'cup', 'butter, sifted'], '102 g'],
  ['generated control 3', ['1/3', 'tbsp', 'butter, sifted'], '4.3 g']],
 [['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['regression: ingredient name normalization', ['100', 'ml', '  Brown Sugar '], '61 g'],
  ['repair check: ingredient name normalization', ['5', 'tbsp', '  Sugar '], '63 g'],
  ['generated control 1', ['3', 'tbsp', 'butter, sifted'], '38 g'],
  ['generated control 2', ['120', 'cup', 'PACKED SUGAR'], '24000 g'],
  ['generated control 3', ['120', 'tsp', '  Packed Honey '], '850 g']],
 [['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
  ['regression: ingredient name normalization', ['2', 'tbsp', '  Water '], '30 g'],
  ['repair check: ingredient name normalization', ['15', 'ml', '  Packed Flour '], '7.6 g'],
  ['generated control 1', ['6', 'cup', 'butter'], '1362 g'],
  ['generated control 2', ['4', 'ml', 'water'], '4.0 g'],
  ['generated control 3', ['1/2', 'ml', 'saffron'], 'error: unknown ingredient']],
 [['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
  ['one cup flour', ['1', 'cup', 'flour'], '120 g'],
  ['regression: ingredient name normalization', ['4', 'ml', 'WATER'], '4.0 g'],
  ['repair check: ingredient name normalization', ['4', 'tsp', '  Honey, Sifted '], '26 g'],
  ['generated control 1', ['2', 'ml', 'flour, sifted'], '0.9 g'],
  ['generated control 2', ['3', 'cup', 'honey'], '1020 g'],
  ['generated control 3', ['1/4', 'tsp', 'HONEY'], '1.8 g']]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), 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
one cup flour120 g120 gPassed
exactly ten grams10 g10 gPassed
packed brown sugar213 g213 gPassed
regression: ingredient name normalizationerror: unknown ingredient8.6 gFailed
repair check: ingredient name normalizationerror: unknown ingredient91 gFailed
generated control 10.2 g0.2 gPassed
generated control 2850 g850 gPassed
generated control 3error: unknown uniterror: unknown unitPassed

SHA-256 / abe1812737e6ccf887203d38f538a2b56eb21e0288fce29f0869bd165290a2f2

3 / The verified repair

Exit 0
"""Failure Map reference implementation. Python standard library only."""
import json
import math
from fractions import Fraction
N = 1
observations = []
def solve(amount, unit, ingredient):
    DENS = {'flour': 120, 'sugar': 200, 'brown sugar': 145, 'butter': 227, 'honey': 340, 'water': 236}
    PER_CUP = {'cup': 1, 'tbsp': 16, 'tsp': 48}
    name = ingredient.strip().lower()
    packed = name.startswith('packed ')
    if packed:
        name = name[len('packed '):]
    sifted = name.endswith(', sifted')
    if sifted:
        name = name[:-len(', sifted')]
    if name not in DENS:
        return 'error: unknown ingredient'
    if unit == 'ml':
        cups = Fraction(amount) / Fraction(2365, 10)
    elif unit in PER_CUP:
        cups = Fraction(amount) / PER_CUP[unit]
    else:
        return 'error: unknown unit'
    d = Fraction(DENS[name])
    if packed and name == 'brown sugar':
        d = Fraction(213)
    if sifted:
        d = d * Fraction(9, 10)
    g = cups * d
    if g < 10:
        return '%.1f g' % (math.floor(g * 10 + Fraction(1, 2)) / 10)
    return '%d g' % math.floor(g + Fraction(1, 2))
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['one cup flour', ['1', 'cup', 'flour'], '120 g'], ['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
  ['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['regression: ingredient name normalization', ['6', 'ml', '  Honey '], '8.6 g'],
  ['repair check: ingredient name normalization', ['120', 'ml', '  Sugar, Sifted '], '91 g'],
  ['generated control 1', ['1/4', 'ml', 'sugar'], '0.2 g'],
  ['generated control 2', ['4', 'cup', 'water, sifted'], '850 g'],
  ['generated control 3', ['250', 'pinch', 'brown sugar'], 'error: unknown unit']],
 [['exactly ten grams', ['4', 'tsp', 'flour'], '10 g'],
  ['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['regression: ingredient name normalization', ['1/4', 'ml', '  Flour, Sifted '], '0.1 g'],
  ['repair check: ingredient name normalization', ['5', 'ml', '  Butter, Sifted '], '4.3 g'],
  ['generated control 1', ['6', 'ml', 'saffron'], 'error: unknown ingredient'],
  ['generated control 2', ['1/2', 'cup', 'butter, sifted'], '102 g'],
  ['generated control 3', ['1/3', 'tbsp', 'butter, sifted'], '4.3 g']],
 [['packed brown sugar', ['1', 'cup', 'packed brown sugar'], '213 g'],
  ['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['regression: ingredient name normalization', ['100', 'ml', '  Brown Sugar '], '61 g'],
  ['repair check: ingredient name normalization', ['5', 'tbsp', '  Sugar '], '63 g'],
  ['generated control 1', ['3', 'tbsp', 'butter, sifted'], '38 g'],
  ['generated control 2', ['120', 'cup', 'PACKED SUGAR'], '24000 g'],
  ['generated control 3', ['120', 'tsp', '  Packed Honey '], '850 g']],
 [['unknown ingredient', ['1', 'cup', 'saffron'], 'error: unknown ingredient'],
  ['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
  ['regression: ingredient name normalization', ['2', 'tbsp', '  Water '], '30 g'],
  ['repair check: ingredient name normalization', ['15', 'ml', '  Packed Flour '], '7.6 g'],
  ['generated control 1', ['6', 'cup', 'butter'], '1362 g'],
  ['generated control 2', ['4', 'ml', 'water'], '4.0 g'],
  ['generated control 3', ['1/2', 'ml', 'saffron'], 'error: unknown ingredient']],
 [['metric cup of water', ['250', 'ml', 'water'], '249 g'],
  ['sifted flour tablespoon', ['2', 'tbsp', 'Flour, sifted'], '14 g'],
  ['one cup flour', ['1', 'cup', 'flour'], '120 g'],
  ['regression: ingredient name normalization', ['4', 'ml', 'WATER'], '4.0 g'],
  ['repair check: ingredient name normalization', ['4', 'tsp', '  Honey, Sifted '], '26 g'],
  ['generated control 1', ['2', 'ml', 'flour, sifted'], '0.9 g'],
  ['generated control 2', ['3', 'cup', 'honey'], '1020 g'],
  ['generated control 3', ['1/4', 'tsp', 'HONEY'], '1.8 g']]]
for label, args, expected in fixtures[N - 1]:
    check(label, solve(*args), 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
one cup flour120 g120 gPassed
exactly ten grams10 g10 gPassed
packed brown sugar213 g213 gPassed
regression: ingredient name normalization8.6 g8.6 gPassed
repair check: ingredient name normalization91 g91 gPassed
generated control 10.2 g0.2 gPassed
generated control 2850 g850 gPassed
generated control 3error: unknown uniterror: unknown unitPassed

SHA-256 / 1eb63a5c71205e8cd4163c8eea905c169ae9de108c679c702c037d80f2823e3d

Verification & scope

A deterministic toy contract stated in full here; it is a bounded teaching model, not an authoritative reference or standards implementation. 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:27.036945+00:00.

Case digest / 9758e19a9dc200de7b34d359378f4263dfe22ac7e29e830ce2883c0262691729