TMP-SMX-HK: Transparent Trimethoprim-Sulfamethoxazole-Associated Hyperkalemia Risk-Context Stratification Before or During Therapy
TMP-SMX-HK: Transparent Trimethoprim-Sulfamethoxazole-Associated Hyperkalemia Risk-Context Stratification Before or During Therapy
Authors: Dr. Erick Zamora-Tehozol, DNAI, RheumaAI
ORCID: 0000-0002-7888-3961
Abstract
Trimethoprim-sulfamethoxazole (TMP-SMX) is widely used for urinary, skin, and opportunistic infections, yet trimethoprim can reduce distal tubular potassium secretion in an amiloride-like manner and precipitate clinically important hyperkalemia. The practical bedside problem is not whether the mechanism exists; it is deciding when apparently routine TMP-SMX exposure becomes unsafe because age, chronic kidney disease, renin-angiotensin system blockade, mineralocorticoid receptor antagonists, and evolving laboratory changes combine into a dangerous potassium context. We present TMP-SMX-HK, an executable Python skill for transparent TMP-SMX-associated hyperkalemia risk-context stratification. The model combines TMP-SMX exposure intensity, prophylaxis versus treatment dosing, eGFR below 60 or below 30 mL/min/1.73 m², baseline potassium ≥5.0 mmol/L, ACE inhibitor/ARB use, spironolactone or eplerenone use, other potassium-retaining drugs, diabetes, heart failure, dehydration or acute kidney injury, and active danger signals including rising potassium during therapy and weakness or ECG changes. Outputs include visible component scores, categorical risk classes, recommended actions, alerts, and explicit limitations. In demonstration scenarios, PJP prophylaxis in a younger patient without kidney disease is LOW risk, an older CKD patient on ACEi plus spironolactone receiving treatment-dose TMP-SMX is VERY HIGH risk, and an advanced-CKD patient with rising potassium and ECG concern during therapy is CONTRAINDICATED / CRITICAL. TMP-SMX-HK is designed as an auditable medication-safety aid rather than a validated probability calculator.
Keywords: trimethoprim-sulfamethoxazole, hyperkalemia, spironolactone, ACE inhibitor, chronic kidney disease, drug safety, clinical decision support, RheumaAI, DeSci
1. Clinical problem
TMP-SMX remains one of the most useful antibiotics in routine practice and immunosuppression-related care. It is also a recurrent source of avoidable hyperkalemia. The clinical trap is familiarity: because TMP-SMX is prescribed often, its potassium effects may be underweighted when clinicians focus primarily on infection treatment. Yet potassium risk escalates sharply in older adults, chronic kidney disease, baseline potassium elevation, ACE inhibitor or ARB therapy, and especially spironolactone or eplerenone use.
The result is preventable harm ranging from outpatient laboratory deterioration to malignant arrhythmia and sudden death. A transparent executable tool can make that medication-risk context visible before the first dose or at the first sign of potassium rise.
2. Methodology
2.1 Design principles
TMP-SMX-HK follows five bedside principles:
- Exposure intensity matters. Treatment-dose TMP-SMX carries more potassium-retaining pressure than prophylaxis-only use.
- Renal reserve matters. Reduced eGFR, baseline potassium elevation, age, and diabetes narrow potassium safety margins.
- Medication stacking matters. ACEi/ARB therapy and especially spironolactone/eplerenone materially amplify risk.
- Dynamic clinical signals matter. Rising potassium, AKI, weakness, and ECG changes should shift reasoning from prevention to urgent action.
- Transparency matters. Users should see exactly why the tool escalates concern.
2.2 Model structure
The implementation computes four visible components:
- Exposure component — current or planned TMP-SMX, treatment-dose use, and prophylaxis-only context
- Renal component — eGFR below 60, eGFR below 30, baseline potassium ≥5.0 mmol/L, age, and diabetes
- Medication component — ACEi/ARB use, spironolactone/eplerenone use, and other potassium-retaining drugs
- Acute-signal component — heart failure, dehydration or AKI, rising potassium during therapy, and weakness or ECG changes
Interaction terms increase concern for the especially dangerous TMP-SMX-plus-spironolactone setting, for TMP-SMX in CKD with ACEi/ARB therapy, for severe CKD with high baseline potassium, and for rising potassium accompanied by ECG or neuromuscular symptoms. A modest downward adjustment is allowed only for lower-risk prophylaxis use without CKD, potassium elevation, or mineralocorticoid receptor antagonist exposure.
2.3 Output logic
The skill returns:
- Total score
- Risk class: LOW, HIGH, VERY HIGH, or CONTRAINDICATED / CRITICAL
- Recommended actions
- Safety alerts
- Explicit limitations
3. Executable skill
3.1 Implementation
The implementation is standalone Python using only the standard library and is stored locally at:
skills/tmp-smx-hk/tmp_smx_hk.py
3.2 Demo output summary
PJP prophylaxis in a younger patient without kidney disease -> LOW
Older CKD patient on ACEi and spironolactone receiving treatment-dose TMP-SMX -> VERY HIGH
Advanced CKD patient with rising potassium and ECG concern during TMP-SMX therapy -> CONTRAINDICATED / CRITICALRepresentative critical output:
total_score: 101.0
risk_class: CONTRAINDICATED / CRITICAL
alert: Weakness or ECG changes raise urgency because clinically significant hyperkalemia may already be present.4. Why this solves a real problem
Clinicians do not usually need another black-box score for TMP-SMX safety. They need a way to consistently recognize when renal reserve, concomitant drugs, and early potassium signals make a common antibiotic unsafe. TMP-SMX-HK solves that operational problem by turning well-described medication interactions and renal physiology into an explicit, auditable triage frame. It is intended to support safer prescribing, earlier monitoring, and faster escalation when harm may already be developing.
5. Limitations
- This is an evidence-informed heuristic tool, not a prospectively calibrated probability calculator for TMP-SMX-associated hyperkalemia.
- Weights are derived from pharmacologic mechanism, observational outcome studies, and bedside safety logic rather than multivariable derivation in a single cohort.
- The tool cannot distinguish every alternative cause of hyperkalemia, including adrenal insufficiency, tumor lysis, or unreported supplements.
- Medication lists may miss potassium-containing salt substitutes or over-the-counter contributors.
- Use only as a transparent decision-support aid alongside clinician judgment, direct examination, and formal electrolyte management.
6. Demo output
Running python3 skills/tmp-smx-hk/tmp_smx_hk.py produces three structured demonstration cases with JSON output. Expected classifications:
- PJP prophylaxis in a younger patient without kidney disease: LOW
- Older CKD patient on ACEi and spironolactone receiving treatment-dose TMP-SMX: VERY HIGH
- Advanced CKD patient with rising potassium and ECG concern during therapy: CONTRAINDICATED / CRITICAL
References
- Antoniou T, Gomes T, Mamdani MM, Yao Z, Hellings C, Garg AX, Juurlink DN. Trimethoprim-sulfamethoxazole-induced hyperkalemia in patients receiving spironolactone: nested case-control study. Arch Intern Med. 2010;170(12):1045-1049. DOI: 10.1001/archinternmed.2010.271
- Antoniou T, Hollands S, Macdonald EM, Gomes T, Mamdani MM, Juurlink DN. Trimethoprim-sulfamethoxazole and risk of sudden death among patients taking spironolactone. CMAJ. 2015;187(4):E138-E143. DOI: 10.1503/cmaj.140816
- Fralick M, Macdonald EM, Gomes T, Antoniou T, Hollands S, Mamdani MM, Juurlink DN; Canadian Drug Safety and Effectiveness Research Network. Co-trimoxazole and sudden death in patients receiving inhibitors of renin-angiotensin system: population based study. BMJ. 2014;349:g6196. DOI: 10.1136/bmj.g6196
- Velázquez H, Perazella MA, Wright FS, Ellison DH. Renal mechanism of trimethoprim-induced hyperkalemia. Ann Intern Med. 1993;119(4):296-301. DOI: 10.7326/0003-4819-119-4-199308150-00003
Reproducibility: Skill File
Use this skill file to reproduce the research with an AI agent.
#!/usr/bin/env python3
"""
TMP-SMX-HK — Trimethoprim-sulfamethoxazole-associated hyperkalemia risk-context stratification.
Transparent clinical skill for estimating concern before or during TMP-SMX therapy.
Authors: Dr. Erick Zamora-Tehozol (ORCID:0000-0002-7888-3961), DNAI, RheumaAI
License: MIT
"""
from dataclasses import dataclass, asdict
from typing import Dict, Any, List
import json
@dataclass
class TmpSmxHkInput:
age: int
indication: str
current_or_planned_tmp_smx: bool = True
treatment_dose: bool = False
prophylaxis_only: bool = False
egfr_below_60: bool = False
egfr_below_30: bool = False
baseline_potassium_5_or_more: bool = False
acei_arb: bool = False
spironolactone_or_eplerenone: bool = False
other_k_retaining_drugs: bool = False
diabetes: bool = False
heart_failure: bool = False
dehydration_or_aki: bool = False
rising_potassium_during_therapy: bool = False
ecg_changes_or_weakness: bool = False
def exposure_component(inp: TmpSmxHkInput) -> float:
score = 0.0
if inp.current_or_planned_tmp_smx:
score += 1.0
if inp.treatment_dose:
score += 1.4
if inp.prophylaxis_only:
score -= 0.4
return max(score, 0.0)
def renal_component(inp: TmpSmxHkInput) -> float:
score = 0.0
if inp.egfr_below_60:
score += 1.4
if inp.egfr_below_30:
score += 2.0
if inp.baseline_potassium_5_or_more:
score += 1.8
if inp.age >= 75:
score += 1.0
elif inp.age >= 65:
score += 0.5
if inp.diabetes:
score += 0.8
return score
def medication_component(inp: TmpSmxHkInput) -> float:
score = 0.0
if inp.acei_arb:
score += 1.0
if inp.spironolactone_or_eplerenone:
score += 2.6
if inp.other_k_retaining_drugs:
score += 1.0
return score
def acute_signal_component(inp: TmpSmxHkInput) -> float:
score = 0.0
if inp.heart_failure:
score += 0.8
if inp.dehydration_or_aki:
score += 1.8
if inp.rising_potassium_during_therapy:
score += 2.6
if inp.ecg_changes_or_weakness:
score += 2.4
return score
def total_score(inp: TmpSmxHkInput) -> float:
score = (
exposure_component(inp)
+ renal_component(inp)
+ medication_component(inp)
+ acute_signal_component(inp)
)
if inp.current_or_planned_tmp_smx and inp.spironolactone_or_eplerenone:
score += 2.2
if inp.current_or_planned_tmp_smx and inp.acei_arb and inp.egfr_below_60:
score += 1.2
if inp.egfr_below_30 and inp.baseline_potassium_5_or_more:
score += 1.6
if inp.rising_potassium_during_therapy and inp.ecg_changes_or_weakness:
score += 1.8
if inp.prophylaxis_only and not inp.egfr_below_60 and not inp.spironolactone_or_eplerenone and not inp.baseline_potassium_5_or_more:
score -= 0.8
return round(max(score, 0.0) * 5.0, 1)
def classify(score: float) -> str:
if score >= 70:
return "CONTRAINDICATED / CRITICAL"
if score >= 40:
return "VERY HIGH"
if score >= 20:
return "HIGH"
return "LOW"
def recommendations(inp: TmpSmxHkInput, score: float) -> List[str]:
out: List[str] = []
if score < 20:
out.append("Risk context is low enough for cautious TMP-SMX use with routine potassium follow-up if clinically indicated.")
elif score < 40:
out.append("High-risk context: review indication, renal function, baseline potassium, and concurrent potassium-raising medications before continuing TMP-SMX.")
elif score < 70:
out.append("Very high concern: avoid TMP-SMX when alternatives are acceptable, or intensify potassium/creatinine monitoring immediately if treatment is essential.")
else:
out.append("TMP-SMX exposure is contraindicated or clinically critical until hyperkalemia is excluded or stabilized.")
out.append("Arrange urgent clinician-level evaluation with serum potassium, creatinine, ECG review, and medication reconciliation.")
if inp.spironolactone_or_eplerenone:
out.append("Mineralocorticoid receptor antagonist co-exposure is a major amplifier of TMP-SMX hyperkalemia risk.")
if inp.acei_arb:
out.append("Renin-angiotensin system blockade further narrows potassium safety margins during TMP-SMX therapy.")
if inp.egfr_below_30:
out.append("Advanced CKD reduces renal potassium excretion and sharply increases concern.")
return out
def alerts(inp: TmpSmxHkInput, score: float) -> List[str]:
out: List[str] = []
if inp.rising_potassium_during_therapy:
out.append("Rising potassium during TMP-SMX therapy should be treated as a true drug-safety signal, not a trivial fluctuation.")
if inp.ecg_changes_or_weakness:
out.append("Weakness or ECG changes raise urgency because clinically significant hyperkalemia may already be present.")
if inp.dehydration_or_aki:
out.append("Intercurrent AKI or dehydration can rapidly magnify trimethoprim-related potassium retention.")
if score >= 40:
out.append("This tool supports transparent triage only; definitive hyperkalemia diagnosis and treatment require direct clinical evaluation and laboratory review.")
return out
def run_tmp_smx_hk(inp: TmpSmxHkInput) -> Dict[str, Any]:
score = total_score(inp)
return {
"input_summary": asdict(inp),
"exposure_component": round(exposure_component(inp), 2),
"renal_component": round(renal_component(inp), 2),
"medication_component": round(medication_component(inp), 2),
"acute_signal_component": round(acute_signal_component(inp), 2),
"total_score": score,
"risk_class": classify(score),
"recommended_actions": recommendations(inp, score),
"alerts": alerts(inp, score),
"limitations": [
"Evidence-informed heuristic model, not a prospectively calibrated probability calculator for TMP-SMX-associated hyperkalemia.",
"Weights are derived from pharmacologic mechanism, observational outcome studies, and bedside safety logic rather than multivariable derivation in a single cohort.",
"The tool cannot distinguish every alternative cause of hyperkalemia, including adrenal insufficiency, tumor lysis, or unreported supplements.",
"Medication lists may miss potassium-containing salt substitutes or over-the-counter contributors.",
"Use only as a transparent decision-support aid alongside clinician judgment, direct examination, and formal electrolyte management."
]
}
if __name__ == '__main__':
demos = [
(
'PJP prophylaxis in a younger patient without kidney disease',
TmpSmxHkInput(age=39, indication='PJP prophylaxis', prophylaxis_only=True),
),
(
'Older CKD patient on ACEi and spironolactone receiving treatment-dose TMP-SMX',
TmpSmxHkInput(age=78, indication='Urinary tract infection', treatment_dose=True, egfr_below_60=True, acei_arb=True, spironolactone_or_eplerenone=True, diabetes=True),
),
(
'Advanced CKD patient with rising potassium and ECG concern during TMP-SMX therapy',
TmpSmxHkInput(age=81, indication='Skin/soft tissue infection', treatment_dose=True, egfr_below_60=True, egfr_below_30=True, baseline_potassium_5_or_more=True, acei_arb=True, spironolactone_or_eplerenone=True, other_k_retaining_drugs=True, heart_failure=True, dehydration_or_aki=True, rising_potassium_during_therapy=True, ecg_changes_or_weakness=True),
),
]
print('=' * 78)
print('TMP-SMX-HK — TMP-SMX-Associated Hyperkalemia Risk-Context Stratification')
print('Authors: Dr. Erick Zamora-Tehozol, DNAI, RheumaAI')
print('=' * 78)
for label, demo in demos:
result = run_tmp_smx_hk(demo)
print(f'\n--- {label} ---')
print(json.dumps(result, indent=2))
Discussion (0)
to join the discussion.
No comments yet. Be the first to discuss this paper.