FAILURE MAP
← Case archive

FA-64206 / Medication dosing calculations / Open access

Concentration and electrolyte unit conversions: ratio strength orientation · case 01

A 1:1000 solution is reported as 0.001 mg/mL.

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

ROOT CAUSE

The ratio gives grams per mL, but the gram-to-milligram factor is missing.

VERIFIED REPAIR

Compute a*1000/b mg/mL.

Unsuccessful approach: Assuming a numerator of 1 misreports ratios such as 2:1000.

Case contract

Input {kind, value, mw?, valence?}. kind "pct": w/v percent to mg/mL (x10). kind "ratio": "a:b" ratio strength (a g in b mL) to mg/mL = a*1000/b, whitespace around parts allowed. kind "meq_to_mg": mg = mEq*mw/|valence|. kind "mmol_to_meq": mEq = mmol*|valence|. Any other kind returns {error: UNKNOWN_KIND}. Otherwise {result} rounded to 4 decimals.

Why this case matters

Strength labels mix percent, ratio and equivalent units; each conversion has its own orientation and sign rule.

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(x):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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
percent solution{'result': 9.0}{'result': 9.0}Passed
one in ten thousand{'result': 0.0001}{'result': 0.1}Failed
ratio with numerator above one{'result': 0.002}{'result': 2.0}Failed
divalent cation mEq to mg{'result': 200.4}{'result': 200.4}Passed
anion mEq to mg{'result': 709.0}{'result': 709.0}Passed
mmol of anion to mEq{'result': 10.0}{'result': 10.0}Passed
mmol of monovalent cation{'result': 8.0}{'result': 8.0}Passed
unknown conversion kind{'error': 'UNKNOWN_KIND'}{'error': 'UNKNOWN_KIND'}Passed

SHA-256 / 6849c3c1937d17f394a6fb658c8a296118e3f8fb8d6b7f740e3e55ec54ade3e3

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(x):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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
percent solution{'result': 9.0}{'result': 9.0}Passed
one in ten thousand{'result': 0.1}{'result': 0.1}Passed
ratio with numerator above one{'result': 1.0}{'result': 2.0}Failed
divalent cation mEq to mg{'result': 200.4}{'result': 200.4}Passed
anion mEq to mg{'result': 709.0}{'result': 709.0}Passed
mmol of anion to mEq{'result': 10.0}{'result': 10.0}Passed
mmol of monovalent cation{'result': 8.0}{'result': 8.0}Passed
unknown conversion kind{'error': 'UNKNOWN_KIND'}{'error': 'UNKNOWN_KIND'}Passed

SHA-256 / 0ff14bd11abdeccf0819c75472c355f65a6c2ac5b64c83005bb070ab25720212

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(x):
    k, v = x['kind'], x['value']
    if k == 'pct':
        r = Fraction(str(v)) * 10
    elif k == 'ratio':
        a, b = [Fraction(p.strip()) for p in v.split(':')]
        r = a * 1000 / b
    elif k == 'meq_to_mg':
        r = Fraction(str(v)) * Fraction(str(x['mw'])) / abs(x['valence'])
    elif k == 'mmol_to_meq':
        r = Fraction(str(v)) * abs(x['valence'])
    else:
        return {'error': 'UNKNOWN_KIND'}
    return {'result': round(float(r), 4)}
def check(label, actual, expected):
    observations.append({"check": label, "actual": actual, "expected": expected, "passed": actual == expected})
fixtures = [[('percent solution', {'kind': 'pct', 'value': '0.9'}, {'result': 9.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:10000'}, {'result': 0.1}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '2 : 1000'}, {'result': 2.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 10, 'mw': '40.08', 'valence': 2},
   {'result': 200.4}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -1}, {'result': 709.0}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 5, 'valence': -2}, {'result': 10.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 8, 'valence': 1}, {'result': 8.0}),
  ('unknown conversion kind', {'kind': 'mcg', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '5'}, {'result': 50.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:20000'}, {'result': 0.05}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '3 : 1000'}, {'result': 3.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 20, 'mw': '40.08', 'valence': 2},
   {'result': 400.8}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -2}, {'result': 354.5}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 10, 'valence': -2}, {'result': 20.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 9, 'valence': 1}, {'result': 9.0}),
  ('unknown conversion kind', {'kind': 'iu', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '2'}, {'result': 20.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:30000'}, {'result': 0.0333}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '4 : 1000'}, {'result': 4.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 30, 'mw': '40.08', 'valence': 2},
   {'result': 601.2}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -3}, {'result': 236.3333}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 15, 'valence': -2}, {'result': 30.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 10, 'valence': 1}, {'result': 10.0}),
  ('unknown conversion kind', {'kind': 'pct ', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '0.45'}, {'result': 4.5}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:40000'}, {'result': 0.025}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '5 : 1000'}, {'result': 5.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 40, 'mw': '40.08', 'valence': 2},
   {'result': 801.6}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -4}, {'result': 177.25}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 20, 'valence': -2}, {'result': 40.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 11, 'valence': 1}, {'result': 11.0}),
  ('unknown conversion kind', {'kind': 'Ratio', 'value': 1}, {'error': 'UNKNOWN_KIND'})],
 [('percent solution', {'kind': 'pct', 'value': '10'}, {'result': 100.0}),
  ('one in ten thousand', {'kind': 'ratio', 'value': '1:50000'}, {'result': 0.02}),
  ('ratio with numerator above one', {'kind': 'ratio', 'value': '6 : 1000'}, {'result': 6.0}),
  ('divalent cation mEq to mg',
   {'kind': 'meq_to_mg', 'value': 50, 'mw': '40.08', 'valence': 2},
   {'result': 1002.0}),
  ('anion mEq to mg', {'kind': 'meq_to_mg', 'value': 20, 'mw': '35.45', 'valence': -5}, {'result': 141.8}),
  ('mmol of anion to mEq', {'kind': 'mmol_to_meq', 'value': 25, 'valence': -2}, {'result': 50.0}),
  ('mmol of monovalent cation', {'kind': 'mmol_to_meq', 'value': 12, 'valence': 1}, {'result': 12.0}),
  ('unknown conversion kind', {'kind': '', 'value': 1}, {'error': 'UNKNOWN_KIND'})]]
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
percent solution{'result': 9.0}{'result': 9.0}Passed
one in ten thousand{'result': 0.1}{'result': 0.1}Passed
ratio with numerator above one{'result': 2.0}{'result': 2.0}Passed
divalent cation mEq to mg{'result': 200.4}{'result': 200.4}Passed
anion mEq to mg{'result': 709.0}{'result': 709.0}Passed
mmol of anion to mEq{'result': 10.0}{'result': 10.0}Passed
mmol of monovalent cation{'result': 8.0}{'result': 8.0}Passed
unknown conversion kind{'error': 'UNKNOWN_KIND'}{'error': 'UNKNOWN_KIND'}Passed

SHA-256 / 9583d0428d501b313196ff6113812df9e04cb2fae429b6f9b0f02e1e1a6de5ed

Verification & scope

A deterministic toy software model with explicitly stipulated thresholds and formulas; it is not clinical guidance, not a validated medical calculator, and makes no claim of conformance to any published protocol. Numbered variants vary patient and order inputs. 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:47:22.034149+00:00.

Case digest / 7bacb2d7b54db9792a33b872a107bedb6f3f86150e0e58c6c5df1306b156c43d