Skip to content

Keep doses linked to their treatments - #142

Draft
Airwhale wants to merge 9 commits into
shaun/fix-canonicalize-batch-splitfrom
codex/match-treatment-dose-pairs
Draft

Keep doses linked to their treatments#142
Airwhale wants to merge 9 commits into
shaun/fix-canonicalize-batch-splitfrom
codex/match-treatment-dose-pairs

Conversation

@Airwhale

@Airwhale Airwhale commented Aug 25, 2026

Copy link
Copy Markdown
Collaborator

#120 -> #142 -> #141

Why

The variable-extraction pipeline currently returns dosage as a flat list. When a post names several treatments, downstream code cannot tell whether 4.5 mg belongs to LDN or B12. Matching separate treatment and dose lists by position would silently create false records.

Approach taken

  • Require new dosage values to use treatment: dose pairs.
  • Add prompt rules that prohibit assigning a dose by textual proximity or list position.
  • Validate each pair with a Pydantic v2 TreatmentValuePair boundary model.
  • Reject unlinked dosage values in new extraction records instead of guessing a treatment.
  • Preserve the structured dosage field in records.csv and add aligned dosage_treatment and dosage_value columns during normalization.
  • Keep bare dosage values readable when normalizing legacy CSV files, with a blank treatment column that explicitly marks the missing attribution.
  • Exclude the raw dosage pair, treatment name, and high-cardinality dose value from clustering.
  • Update schema and methods documentation and add regression coverage.

User-facing changes

  • dosage now contains entries such as LDN: 4.5 mg and B12: 250 mcg instead of unattached values such as 4.5 mg and 250 mcg.
  • Unlinked doses from malformed model output are dropped instead of guessed.
  • The normalize command adds dosage_treatment and dosage_value columns for direct analysis and joins.
  • Existing flat dosage values remain visible when older CSV output is normalized, with a blank dosage_treatment value.

Closes #128

Shaun added 2 commits August 25, 2026 10:51
Replace flat dosage values with validated treatment: dose pairs so posts that mention multiple interventions cannot be matched by list position or textual proximity.

Add a Pydantic v2 treatment-value boundary model, reject unlinked values in new extraction records, and decompose the structured CSV field into aligned dosage_treatment and dosage_value columns. Preserve bare legacy dosage values with a blank treatment rather than inventing an attribution.

Cover prompt behavior, multi-treatment extraction through CSV export, malformed values, legacy normalization, and clustering exclusions. Update the schema and methods documentation.
Keep the Pydantic treatment-value boundary, but remove the callback-based generic normalizer and decomposer. Normalize dosage pairs directly and place dosage CSV decomposition beside the existing treatment-outcome normalization code.

The JSON and CSV contracts are unchanged: new records still require treatment: dose pairs, and legacy bare doses still produce a blank treatment column. The full suite remains green.
Shaun added 2 commits August 25, 2026 15:16
Split the dosage prompt guidance into explicit evidence, treatment linkage, formatting, and omission decisions. Exclude prescribed-but-unstarted, planned, declined, third-party, and general-information doses so structured output represents treatment exposure rather than nearby dosage text.

Add prompt contract coverage for the negative examples and align the shipped schema description with the author-exposure requirement.
Delete the explanatory comment above dosage pair normalization and shorten the dosage decomposition docstring by removing the legacy bare-dose sentence. Runtime behavior and tests remain unchanged.
Airwhale pushed a commit that referenced this pull request Aug 27, 2026
Add a validated Pipeline B record boundary and shared study paths so analyses run reliably from the repository root or against versioned outputs. Summarize explicit treatment-linked dosages and administration routes by compound, centralize dose attribution helpers, and remove the audit script's source exec.

Update the workbook and runbook for the #142/#141 stack, fresh caches, group attribution guarding, and versioned extraction artifacts. Add focused contract tests for stale CSV rejection, pair alignment, derivative precedence, and single-letter compound attribution.
Airwhale pushed a commit that referenced this pull request Sep 3, 2026
Add a validated Pipeline B record boundary and shared study paths so analyses run reliably from the repository root or against versioned outputs. Summarize explicit treatment-linked dosages and administration routes by compound, centralize dose attribution helpers, and remove the audit script's source exec.

Update the workbook and runbook for the #142/#141 stack, fresh caches, group attribution guarding, and versioned extraction artifacts. Add focused contract tests for stale CSV rejection, pair alignment, derivative precedence, and single-letter compound attribution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants