FAILURE MAP
← Case archive

FA-96886 / Recipe scaling and nutrition / Open access

Nutrition label rounding: sodium band steps · case 01

142.5 mg sodium prints 145 mg and 12.5 mg prints 10 mg.

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

ROOT CAUSE

The 5 mg and 10 mg steps are swapped between the low and high sodium bands.

THE FAILURE

The 5 mg and 10 mg steps are swapped between the low and high sodium bands.

Unsuccessful approach: Switching to 10 mg steps at 100 mg rounds 100-140 mg too coarsely.

Case contract

Round a panel dict to displayed strings (toy label rules, half-up): calories <5 -> 0, <=50 -> nearest 5, else nearest 10; fat g <0.5 -> 0, <5 -> nearest 0.5, else nearest 1; sodium mg <5 -> 0, <=140 -> nearest 5, else nearest 10; cholesterol mg <2 -> "0 mg", <5 -> "less than 5 mg", else nearest 5; carbs g <0.5 -> "0 g", <1 -> "less than 1 g", else nearest 1. Absent keys are omitted. Values print with %g formatting.

Why this case matters

Packaged food and meal-kit labels are generated from recipe nutrition totals with banded rounding rules that differ per nutrient.

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(panel):
    def near(x, step):
        return math.floor(x / step + Fraction(1, 2)) * step
    def show(v, unit):
        t = format(float(v), 'g')
        return t + ' ' + unit if unit else t
    out = {}
    if 'calories' in panel:
        c = Fraction(str(panel['calories']))
        out['calories'] = show(0 if c < 5 else near(c, 5) if c <= 50 else near(c, 10), '')
    if 'fat' in panel:
        x = Fraction(str(panel['fat']))
        out['fat'] = show(0 if x < Fraction(1, 2) else near(x, Fraction(1, 2)) if x < 5 else near(x, 1), 'g')
    if 'sodium' in panel:
        x = Fraction(str(panel['sodium']))
        out['sodium'] = show(0 if x < 5 else near(x, 10) if x <= 140 else near(x, 5), 'mg')
    if 'cholesterol' in panel:
        x = Fraction(str(panel['cholesterol']))
        out['cholesterol'] = '0 mg' if x < 2 else 'less than 5 mg' if x < 5 else show(near(x, 5), 'mg')
    if 'carbs' in panel:
        x = Fraction(str(panel['carbs']))
        out['carbs'] = '0 g' if x < Fraction(1, 2) else 'less than 1 g' if x < 1 else show(near(x, 1), 'g')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['regression: sodium band steps', [{'carbs': 1, 'fat': 2.75, 'sodium': 96}],
   {'carbs': '1 g', 'fat': '3 g', 'sodium': '95 mg'}],
  ['repair check: sodium band steps', [{'cholesterol': 12, 'fat': 12.5, 'sodium': 102.5}],
   {'cholesterol': '10 mg', 'fat': '13 g', 'sodium': '105 mg'}],
  ['generated control 1', [{'calories': 46, 'fat': 3, 'sodium': 2.25}],
   {'calories': '45', 'fat': '3 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'cholesterol': 2, 'fat': 17.5, 'sodium': 1}],
   {'cholesterol': 'less than 5 mg', 'fat': '18 g', 'sodium': '0 mg'}],
  ['generated control 3', [{'calories': 42.75, 'fat': 8, 'sodium': 7.5}],
   {'calories': '45', 'fat': '8 g', 'sodium': '10 mg'}]],
 [['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['regression: sodium band steps', [{'cholesterol': 4.9, 'fat': 5.25, 'sodium': 145}],
   {'cholesterol': 'less than 5 mg', 'fat': '5 g', 'sodium': '150 mg'}],
  ['repair check: sodium band steps', [{'carbs': 30.4, 'cholesterol': 5, 'fat': 4, 'sodium': 135}],
   {'carbs': '30 g', 'cholesterol': '5 mg', 'fat': '4 g', 'sodium': '135 mg'}],
  ['generated control 1', [{'calories': 54.25, 'cholesterol': 3, 'fat': 10}],
   {'calories': '50', 'cholesterol': 'less than 5 mg', 'fat': '10 g'}],
  ['generated control 2',
   [{'calories': 10.75, 'carbs': 0.5, 'cholesterol': 12, 'fat': 4.75, 'sodium': 137.5}],
   {'calories': '10', 'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '5 g', 'sodium': '140 mg'}],
  ['generated control 3', [{'calories': 56.75, 'carbs': 12.5, 'cholesterol': 2.2, 'fat': 0.4}],
   {'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0 g'}]],
 [['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['regression: sodium band steps', [{'calories': 105, 'cholesterol': 4.9, 'sodium': 145}],
   {'calories': '110', 'cholesterol': 'less than 5 mg', 'sodium': '150 mg'}],
  ['repair check: sodium band steps', [{'calories': 89, 'fat': 4.75, 'sodium': 126}],
   {'calories': '90', 'fat': '5 g', 'sodium': '125 mg'}],
  ['generated control 1', [{'cholesterol': 4.9, 'fat': 1.25}],
   {'cholesterol': 'less than 5 mg', 'fat': '1.5 g'}],
  ['generated control 2', [{'calories': 371.5, 'carbs': 0.5, 'cholesterol': 7.5, 'fat': 6.5, 'sodium': 10}],
   {'calories': '370', 'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '7 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 8.5, 'carbs': 0.2, 'cholesterol': 7.5, 'fat': 6.5, 'sodium': 148}],
   {'calories': '10', 'carbs': '0 g', 'cholesterol': '10 mg', 'fat': '7 g', 'sodium': '150 mg'}]],
 [['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['regression: sodium band steps', [{'carbs': 12.5, 'cholesterol': 5, 'fat': 2.75, 'sodium': 146}],
   {'carbs': '13 g', 'cholesterol': '5 mg', 'fat': '3 g', 'sodium': '150 mg'}],
  ['repair check: sodium band steps',
   [{'calories': 56, 'carbs': 0.9, 'cholesterol': 4.9, 'fat': 2, 'sodium': 112.5}],
   {'calories': '60',
    'carbs': 'less than 1 g',
    'cholesterol': 'less than 5 mg',
    'fat': '2 g',
    'sodium': '115 mg'}],
  ['generated control 1', [{'calories': 2.5, 'carbs': 0.5, 'fat': 17.25, 'sodium': 128}],
   {'calories': '0', 'carbs': 'less than 1 g', 'fat': '17 g', 'sodium': '130 mg'}],
  ['generated control 2', [{'calories': 165.5, 'fat': 13.75, 'sodium': 7.5}],
   {'calories': '170', 'fat': '14 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 59, 'sodium': 93}], {'calories': '60', 'sodium': '95 mg'}]],
 [['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['regression: sodium band steps', [{'calories': 279.5, 'carbs': 30.4, 'cholesterol': 5, 'sodium': 142.5}],
   {'calories': '280', 'carbs': '30 g', 'cholesterol': '5 mg', 'sodium': '140 mg'}],
  ['repair check: sodium band steps', [{'cholesterol': 3, 'fat': 15.5, 'sodium': 112.5}],
   {'cholesterol': 'less than 5 mg', 'fat': '16 g', 'sodium': '115 mg'}],
  ['generated control 1', [{'calories': 286, 'carbs': 0.2, 'fat': 4.75}],
   {'calories': '290', 'carbs': '0 g', 'fat': '5 g'}],
  ['generated control 2', [{'calories': 59.5, 'cholesterol': 5, 'fat': 4.75, 'sodium': 173.5}],
   {'calories': '60', 'cholesterol': '5 mg', 'fat': '5 g', 'sodium': '170 mg'}],
  ['generated control 3', [{'calories': 54, 'carbs': 0.2, 'cholesterol': 3, 'fat': 2.75, 'sodium': 12.5}],
   {'calories': '50', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '3 g', 'sodium': '15 mg'}]]]
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
empty panel{}{}Passed
insignificant calories{'calories': '0', 'fat': '0 g'}{'calories': '0', 'fat': '0 g'}Passed
mid-band sodium{'carbs': 'less than 1 g', 'sodium': '140 mg'}{'carbs': 'less than 1 g', 'sodium': '140 mg'}Passed
regression: sodium band steps{'carbs': '1 g', 'fat': '3 g', 'sodium': '100 mg'}{'carbs': '1 g', 'fat': '3 g', 'sodium': '95 mg'}Failed
repair check: sodium band steps{'cholesterol': '10 mg', 'fat': '13 g', 'sodium': '100 mg'}{'cholesterol': '10 mg', 'fat': '13 g', 'sodium': '105 mg'}Failed
generated control 1{'calories': '45', 'fat': '3 g', 'sodium': '0 mg'}{'calories': '45', 'fat': '3 g', 'sodium': '0 mg'}Passed
generated control 2{'cholesterol': 'less than 5 mg', 'fat': '18 g', 'sodium': '0 mg'}{'cholesterol': 'less than 5 mg', 'fat': '18 g', 'sodium': '0 mg'}Passed
generated control 3{'calories': '45', 'fat': '8 g', 'sodium': '10 mg'}{'calories': '45', 'fat': '8 g', 'sodium': '10 mg'}Passed

SHA-256 / a3afc5c45fa28f0922a08627ebc83b4b70e009a2dbeb4c20270e7f40ac729ddf

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(panel):
    def near(x, step):
        return math.floor(x / step + Fraction(1, 2)) * step
    def show(v, unit):
        t = format(float(v), 'g')
        return t + ' ' + unit if unit else t
    out = {}
    if 'calories' in panel:
        c = Fraction(str(panel['calories']))
        out['calories'] = show(0 if c < 5 else near(c, 5) if c <= 50 else near(c, 10), '')
    if 'fat' in panel:
        x = Fraction(str(panel['fat']))
        out['fat'] = show(0 if x < Fraction(1, 2) else near(x, Fraction(1, 2)) if x < 5 else near(x, 1), 'g')
    if 'sodium' in panel:
        x = Fraction(str(panel['sodium']))
        out['sodium'] = show(0 if x < 5 else near(x, 5) if x < 100 else near(x, 10), 'mg')
    if 'cholesterol' in panel:
        x = Fraction(str(panel['cholesterol']))
        out['cholesterol'] = '0 mg' if x < 2 else 'less than 5 mg' if x < 5 else show(near(x, 5), 'mg')
    if 'carbs' in panel:
        x = Fraction(str(panel['carbs']))
        out['carbs'] = '0 g' if x < Fraction(1, 2) else 'less than 1 g' if x < 1 else show(near(x, 1), 'g')
    return out
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['regression: sodium band steps', [{'carbs': 1, 'fat': 2.75, 'sodium': 96}],
   {'carbs': '1 g', 'fat': '3 g', 'sodium': '95 mg'}],
  ['repair check: sodium band steps', [{'cholesterol': 12, 'fat': 12.5, 'sodium': 102.5}],
   {'cholesterol': '10 mg', 'fat': '13 g', 'sodium': '105 mg'}],
  ['generated control 1', [{'calories': 46, 'fat': 3, 'sodium': 2.25}],
   {'calories': '45', 'fat': '3 g', 'sodium': '0 mg'}],
  ['generated control 2', [{'cholesterol': 2, 'fat': 17.5, 'sodium': 1}],
   {'cholesterol': 'less than 5 mg', 'fat': '18 g', 'sodium': '0 mg'}],
  ['generated control 3', [{'calories': 42.75, 'fat': 8, 'sodium': 7.5}],
   {'calories': '45', 'fat': '8 g', 'sodium': '10 mg'}]],
 [['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['regression: sodium band steps', [{'cholesterol': 4.9, 'fat': 5.25, 'sodium': 145}],
   {'cholesterol': 'less than 5 mg', 'fat': '5 g', 'sodium': '150 mg'}],
  ['repair check: sodium band steps', [{'carbs': 30.4, 'cholesterol': 5, 'fat': 4, 'sodium': 135}],
   {'carbs': '30 g', 'cholesterol': '5 mg', 'fat': '4 g', 'sodium': '135 mg'}],
  ['generated control 1', [{'calories': 54.25, 'cholesterol': 3, 'fat': 10}],
   {'calories': '50', 'cholesterol': 'less than 5 mg', 'fat': '10 g'}],
  ['generated control 2',
   [{'calories': 10.75, 'carbs': 0.5, 'cholesterol': 12, 'fat': 4.75, 'sodium': 137.5}],
   {'calories': '10', 'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '5 g', 'sodium': '140 mg'}],
  ['generated control 3', [{'calories': 56.75, 'carbs': 12.5, 'cholesterol': 2.2, 'fat': 0.4}],
   {'calories': '60', 'carbs': '13 g', 'cholesterol': 'less than 5 mg', 'fat': '0 g'}]],
 [['mid-band sodium', [{'carbs': 0.9, 'sodium': 137.5}], {'carbs': 'less than 1 g', 'sodium': '140 mg'}],
  ['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['regression: sodium band steps', [{'calories': 105, 'cholesterol': 4.9, 'sodium': 145}],
   {'calories': '110', 'cholesterol': 'less than 5 mg', 'sodium': '150 mg'}],
  ['repair check: sodium band steps', [{'calories': 89, 'fat': 4.75, 'sodium': 126}],
   {'calories': '90', 'fat': '5 g', 'sodium': '125 mg'}],
  ['generated control 1', [{'cholesterol': 4.9, 'fat': 1.25}],
   {'cholesterol': 'less than 5 mg', 'fat': '1.5 g'}],
  ['generated control 2', [{'calories': 371.5, 'carbs': 0.5, 'cholesterol': 7.5, 'fat': 6.5, 'sodium': 10}],
   {'calories': '370', 'carbs': 'less than 1 g', 'cholesterol': '10 mg', 'fat': '7 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 8.5, 'carbs': 0.2, 'cholesterol': 7.5, 'fat': 6.5, 'sodium': 148}],
   {'calories': '10', 'carbs': '0 g', 'cholesterol': '10 mg', 'fat': '7 g', 'sodium': '150 mg'}]],
 [['large values', [{'calories': 245, 'cholesterol': 22.5, 'fat': 12.5, 'sodium': 455}],
   {'calories': '250', 'cholesterol': '25 mg', 'fat': '13 g', 'sodium': '460 mg'}],
  ['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['regression: sodium band steps', [{'carbs': 12.5, 'cholesterol': 5, 'fat': 2.75, 'sodium': 146}],
   {'carbs': '13 g', 'cholesterol': '5 mg', 'fat': '3 g', 'sodium': '150 mg'}],
  ['repair check: sodium band steps',
   [{'calories': 56, 'carbs': 0.9, 'cholesterol': 4.9, 'fat': 2, 'sodium': 112.5}],
   {'calories': '60',
    'carbs': 'less than 1 g',
    'cholesterol': 'less than 5 mg',
    'fat': '2 g',
    'sodium': '115 mg'}],
  ['generated control 1', [{'calories': 2.5, 'carbs': 0.5, 'fat': 17.25, 'sodium': 128}],
   {'calories': '0', 'carbs': 'less than 1 g', 'fat': '17 g', 'sodium': '130 mg'}],
  ['generated control 2', [{'calories': 165.5, 'fat': 13.75, 'sodium': 7.5}],
   {'calories': '170', 'fat': '14 g', 'sodium': '10 mg'}],
  ['generated control 3', [{'calories': 59, 'sodium': 93}], {'calories': '60', 'sodium': '95 mg'}]],
 [['small cholesterol', [{'carbs': 12.5, 'cholesterol': 3}],
   {'carbs': '13 g', 'cholesterol': 'less than 5 mg'}],
  ['empty panel', [{}], {}],
  ['insignificant calories', [{'calories': 4.9, 'fat': 0.4}], {'calories': '0', 'fat': '0 g'}],
  ['regression: sodium band steps', [{'calories': 279.5, 'carbs': 30.4, 'cholesterol': 5, 'sodium': 142.5}],
   {'calories': '280', 'carbs': '30 g', 'cholesterol': '5 mg', 'sodium': '140 mg'}],
  ['repair check: sodium band steps', [{'cholesterol': 3, 'fat': 15.5, 'sodium': 112.5}],
   {'cholesterol': 'less than 5 mg', 'fat': '16 g', 'sodium': '115 mg'}],
  ['generated control 1', [{'calories': 286, 'carbs': 0.2, 'fat': 4.75}],
   {'calories': '290', 'carbs': '0 g', 'fat': '5 g'}],
  ['generated control 2', [{'calories': 59.5, 'cholesterol': 5, 'fat': 4.75, 'sodium': 173.5}],
   {'calories': '60', 'cholesterol': '5 mg', 'fat': '5 g', 'sodium': '170 mg'}],
  ['generated control 3', [{'calories': 54, 'carbs': 0.2, 'cholesterol': 3, 'fat': 2.75, 'sodium': 12.5}],
   {'calories': '50', 'carbs': '0 g', 'cholesterol': 'less than 5 mg', 'fat': '3 g', 'sodium': '15 mg'}]]]
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
empty panel{}{}Passed
insignificant calories{'calories': '0', 'fat': '0 g'}{'calories': '0', 'fat': '0 g'}Passed
mid-band sodium{'carbs': 'less than 1 g', 'sodium': '140 mg'}{'carbs': 'less than 1 g', 'sodium': '140 mg'}Passed
regression: sodium band steps{'carbs': '1 g', 'fat': '3 g', 'sodium': '95 mg'}{'carbs': '1 g', 'fat': '3 g', 'sodium': '95 mg'}Passed
repair check: sodium band steps{'cholesterol': '10 mg', 'fat': '13 g', 'sodium': '100 mg'}{'cholesterol': '10 mg', 'fat': '13 g', 'sodium': '105 mg'}Failed
generated control 1{'calories': '45', 'fat': '3 g', 'sodium': '0 mg'}{'calories': '45', 'fat': '3 g', 'sodium': '0 mg'}Passed
generated control 2{'cholesterol': 'less than 5 mg', 'fat': '18 g', 'sodium': '0 mg'}{'cholesterol': 'less than 5 mg', 'fat': '18 g', 'sodium': '0 mg'}Passed
generated control 3{'calories': '45', 'fat': '8 g', 'sodium': '10 mg'}{'calories': '45', 'fat': '8 g', 'sodium': '10 mg'}Passed

SHA-256 / 541291ee32a33f010103c4dfd7cd764fb1692796283cc3b1bde6db474be0c13c

HELD IN THE MEMBER ARCHIVE

The verified repair and its recorded checks are member-only.

This mechanism has 8 recorded checks per implementation. The open-access tier publishes the failure and the unsuccessful fix; the repaired source that passes every check, and the observations that prove it, are available to members.

Every case sharing this mechanism uses the same contract and the same repair, so this one record is held back for all of them.

Member access is invitation-based. Sign in with your invited account to inspect the repair.

Sign in to the archive ↗

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:26.833760+00:00.

Case digest / ee4cc6379ccc33f90abc23ec8d0343add2ed935f9fc0d89be3594a5fa22714c4