Repository navigation
Releases
x12sdk 3.1.0
Security
Found in a review of how the library treats input from someone else; the new
Handling untrusted input
page summarises the protections, and SECURITY.md says how to report a
vulnerability privately.
allow_paths=Falsemakes the reading functions treat input as X12 text
only. Every reading function accepts X12 text or a path to a file, so a
service passing on a string it received could be made to read a file on its
own disk.X12ModelReader,X12SegmentReader,iter_lines,read_lines,
to_dataframe,write_csv,match_claims,match_rowsandchecktake
allow_paths(defaultTrue, unchanged); with it off,checkalso stops
saying whether a path exists. The MCP server and the playground use it.
With paths allowed, only regular files are opened: a named pipe or device
could block forever.- Writing X12 refuses a value that contains a delimiter (X12 injection).
A segment terminator or element separator inside a value ended the element
early, so the rest of the value, for exampleSMITH~NM1*PR*2*OTHER PAYER
in a patient name, was written as new segments.x12()now raises a
ValueErrornaming the field; composite and repeating elements also refuse
the component and repetition separators. - Validation errors no longer quote the rejected value. Pydantic's
messages includedinput_value=..., often PHI, which ends up in logs. The
models now sethide_input_in_errors. - Decimal elements must be plain X12 decimals of at most 18 digits.
Python'sDecimalaccepted forms such as1E+999999999, which made the 835
balancing check fail with a rawdecimal.Overflowand could make writing
build a string of a billion digits. They are now a validation error. - The file cannot choose what is imported. ST01 was put into the name of
the parser module imported for a transaction; it must now be a three-digit
code of a supported set. Unsupported versions and codes are reported
without quoting values that do not look like version identifiers. - An unknown segment is logged by name only when the name looks like a
segment identifier, without a traceback, so a malformed file cannot write
its content into the application's logs. - Interchange delimiters must differ and must not be letters, digits or
spaces (the 4010 repetition position, which holdsU, is exempt). - The MCP server's generators make at most 10,000 claims, members or
patients per call, so an assistant cannot be talked into tying up the
machine. X12ParseExceptionmessages no longer quote the file. 3.0.0 said the
message named the segment, loop and HL "but not the file's content". It
could still include the HL number exactly as written, even when a
malformed file put other text there, and the original error's text, which
can quote a value. Files carry PHI, and error messages end up in logs. The
HL number is now shown only when it is a plain number, and the original
error is named by type only; it is still attached as__cause__.
x12sdk 3.0.0
Loops and segments that the implementation guides let repeat are now lists in
the models, so files that repeat them are no longer rejected or silently
merged. Code that reads these attributes needs updating (usually adding
[0]); the table below lists every one. Written X12 output is unchanged, and
the high-level API (x12sdk.tables, x12sdk.access, matching, generation,
the CLI and the MCP server) is unchanged. Every change in this release was
contributed by jcc004 (#32 to #38, #40).
Changed — breaking
| Transaction | Attribute | Before | After |
|---|---|---|---|
| 5010 837P | Loop2300.loop_2310a |
Optional[Loop2310A] |
Optional[List[Loop2310A]] (max 2) |
| 4010 837P | Loop2300.loop_2305, loop_2310a |
Optional[Loop] |
Optional[List[Loop]] |
| 4010 837P | Loop2320.loop_2330d |
Optional[Loop2330D] |
Optional[List[Loop2330D]] |
| 4010 837P | Loop2400.loop_2420f, loop_2420g |
Optional[Loop] |
Optional[List[Loop]] |
| 4010 837I | Loop2300.loop_2305 |
Optional[Loop2305] |
Optional[List[Loop2305]] |
| 835 | Footer.plb_segment |
Optional[PlbSegment] |
Optional[List[PlbSegment]] |
| 834 | Loop2000.loop_2100e, loop_2100g |
Optional[Loop] |
Optional[List[Loop]] |
| 834 | Loop2310.n3_segment |
Optional[N3Segment] |
Optional[List[N3Segment]]; absent is [], not None |
| 270 | Loop2100C.dtp_segment, Loop2100D.dtp_segment |
Optional[Loop2100DtpSegment] |
Optional[List[Loop2100DtpSegment]] (max 9); absent is [], not None |
| 271 | Loop2110C, Loop2110D: ls_segment, loop_2120c/loop_2120d, le_segment |
three attributes | ls_loop_2120c/ls_loop_2120d: Optional[List[Loop2120CBlock]]/Optional[List[Loop2120DBlock]], each block holding one LS, its 2120 loops and its LE |
| 276, 277 | Loop2000C.loop_2100c |
Loop2100C |
List[Loop2100C] (min_length=1) |
# 837P referring provider
claim.loop_2310a.nm1_segment # 2.x
claim.loop_2310a[0].nm1_segment # 3.0
# 835 provider-level adjustment
footer.plb_segment.adjustment_reason_code_1 # 2.x
footer.plb_segment[0].adjustment_reason_code_1 # 3.0
# 271 benefit-related entity
loop_2110c.loop_2120c[0].nm1_segment # 2.x
loop_2110c.ls_loop_2120c[0].loop_2120c[0].nm1_segment # 3.0
# 276/277 service provider
loop_2000c.loop_2100c.nm1_segment # 2.x
loop_2000c.loop_2100c[0].nm1_segment # 3.0Code that builds these models in Python passes lists; a single instance is not
wrapped for you. A parsed single occurrence is a one-item list.
Other behaviour changes:
- A malformed file that made a parser fail with a bare
KeyError,
TypeError,AttributeErrororLookupErrornow raises
X12ParseException. The message names the segment, the loop and the
current HL (not the file's content) and keeps the original exception as
__cause__. A repeatedBPRin an 835 is a validation error saying so. - A 276 service line with no TRN before it raises a
ValueErrornaming SVC and
TRN (aValidationErroror rawAttributeErrorbefore). Code that catches
onlyValidationErrorwill not see it. - A
DTP,REForMSGplaced afterLEin a 271 (an order violation) used
to be moved before theLSsilently; it is now reported, as an SE
segment-count mismatch. - Model dumps of the 271 2100A loop include
per_segment: []when there is no
PER.
Fixed
- Repeated loops are kept. A claim with two referring providers (837P
2310A), a repeated home health care plan (4010 2305), a repeated 2330D,
2420F or 2420G; an 835 with more than one PLB; an 834 with several 2700
reporting categories (the second used to overwrite the first), several 2100E
or 2100G loops, or two address lines in 2310; a 271 with two
benefit-related entities in one 2120 loop or two LS to LE envelopes in one
2110; a 270 with two DTPs in 2100C or 2100D; and a 276 or 277 with a second
service-provider name loop (twoNM1*1P, as sent during a provider
identifier transition) no longer fail or lose data. - An 835 with no claims (a payment-only or provider-adjustment-only file)
validates:loop_2000defaults to an empty list. - 837I and 4010 837I accept up to 999 service lines, the institutional
guide's limit (it was 50). - 837P: a REF in loop 2310D (supervising provider) no longer fails.
Loop2310DRefSegmentwas built on the name segment instead of the
reference segment. - Segments of valid loops were dropped, or opened the wrong loop, without an
error. Each case now parses and writes back unchanged:- 4010 837P: loops 2010BC (
NM1*QD), 2010BD (NM1*AO) and 2330H
(NM1*DQ) were never routed, because their handlers were not named like
the other loop handlers. - 4010 837I: loop 2010BD (
NM1*QD), the 2310E qualifiers77,LIand
TL, and loop 2330H (NM1*FA, whose handler named a constant that did
not exist) were not routed. AnNM1*QCinside an other subscriber loop
replaced the dependent's own patient name loop 2010CA. - 5010 837P and 837D: the pay-to plan loop 2010AC used the billing
provider's REF class, which rejected2U,FYandNF. It has its own
class now, which also keeps the earlierEI,SY,0Band1G, so
nothing that parsed before is rejected. 5010 837I 2010AC also accepts
REF*EI. - 271: a
PERafter the information source name (2100A) was dropped;
Loop2100Againsper_segment, up to three. - 834: an
NM1*36inside a coordination of benefits loop 2320 also opened a
member employer loop 2100D.
- 4010 837P: loops 2010BC (
- 276: service lines after the first are no longer lost, and a subscriber
with HL04 = 1 that carries its own claims no longer crashes or attaches them
to an earlier subscriber. The 277 gets the same subscriber handling, so a
277 whose HL04 = 1 subscriber carries its own TRN or STC is accepted.
x12sdk 2.4.2
Security
- CSV output no longer lets a spreadsheet run file text as a formula
(CWE-1236, CSV injection). X12 names and free text may start with=,+,
-or@, so a crafted 835 or 837 could put a formula such as
=HYPERLINK(...)into the CSV fromwrite_csv,x12sdk-tableor the
playground's download, where Excel or LibreOffice would run it on opening.
Such text is now prefixed with an apostrophe; plain numbers are unchanged.
write_csv(..., escape_formulas=False)keeps the old output for programs
that read the CSV, and the newx12sdk.tables.spreadsheet_safeapplies the
rule to one value.read_linesandto_dataframeare unchanged. - The playground declares a strict Content Security Policy: it runs only
its own scripts (moved from inline intoapp.js), and the page may not load
or send anything to another site, so injected content could neither run nor
send data anywhere. The Python runtime still loads in its worker from the
pinned Pyodide CDN and PyPI. - Workflows pin every GitHub Action to a commit SHA, so a moved tag cannot
change what runs in CI or the release; Dependabot opens a pull request when
a pinned action has a new release. Continuous integration also declares a
read-only token.
x12sdk 2.4.1
Added
- A browser playground (
playground/, published as a Hugging Face
Space): check a file and see where it breaks, turn an 835 or 837 into a
CSV, generate synthetic files and claim/remittance pairs, and match claims
to payments. It runs the released x12sdk in Pyodide, so files are processed
in the visitor's browser and never uploaded. - A documentation site at https://owgreen-dev.github.io/x12sdk/: task
guides (tables, checking files, generating, matching, reading and writing,
denial analytics, MCP, CLI) and an API reference, built with Sphinx and
Furo fromdocs/. Every Python example on it runs in the test suite
(test_docs.py), and the build fails on any warning.pip install "x12sdk[docs]"installs the tools.
Changed
- Each tagged release is listed in the official MCP Registry automatically
once it is on PyPI, by a workflow authenticated with GitHub OIDC (no stored
secret).glama.jsonnames the maintainer for the Glama directory.
Fixed
The four fixes below were contributed by jcc004
(#27, #28, #29, #30).
- A subscriber loop with HL04 = 1 that carries its own detail segments no
longer crashes or loses its place. The 270, 271 and every 837 parser set
the current patient only when HL04 was 0, so such a subscriber raised a raw
TypeErrororKeyError, or its detail was attached to an earlier
subscriber. The subscriber is now always the current patient until a
dependent loop starts. The 837 parsers accept a claim directly under a
subscriber who also has dependents, and a subscriber with HL04 = 1 and no
dependent; the 270 and 271 still refuse a subscriber with HL04 = 1 and no
dependent, with their existing error. - 271: an empty NM1 last name or organization name is accepted in loops
2100A, 2100B and 2100D, as it already was in 2100C. It failed with a
string_typeerror before; a value is still limited to 60 characters. - 277: segments are no longer dropped while parsing. Every service line
after the first (with its STC and DTP) and the segments after a patient or
claim loop without a TRN were lost, which showed only as an SE segment
count mismatch. They are now kept and round-trip.trn_segmentis
optional on the 2200D and 2200E loops, so a claim without a TRN is
accepted;trace_numberreturns None for it. - 271: well-formed AAA03, AAA04 and EB03 code values are accepted. These
fields were limited to fixed lists, one copy per loop for AAA03 and AAA04,
so a valid code outside a list (for example72or73in AAA03,A8in
EB03) failed the whole transaction. Each list is now defined once, in
x12sdk.v5010.code_tables, and gains72and73(AAA03) andA8(EB03).
AAA03 and AAA04 also accept any other value of the right length. EB03 on
the 271 and EQ01 on the 270 (the same service type code) accept, in each
repetition, a known code, any other value of one or two characters, or an
empty repetition (30^,2^^30), and the file serializes back byte for
byte; a value longer than two characters, or an element empty throughout,
is still rejected. Parsed values are plain strings, unchanged from the
released version. Inputs rejected before are accepted; nothing accepted
before changes, and the nested enum names on the segment classes still
resolve.
x12sdk 2.4.0
Added
-
x12sdk.tablesandx12sdk-table: an 835 or 837 as one row per service
line, for spreadsheets, SQL and pandas.read_lines,to_dataframe
(pandas extra) andwrite_csv;x12sdk-table remit.835 -o remit.csvneeds
nothing extra. Remittance rows carry the payment, claim, patient, procedure,
amounts and adjustments totalled by group plus everyGROUP-REASONcode;
claim rows (837P, 837I, 837D) carry the claim, patient, payer, provider,
diagnoses, revenue codes and teeth. The columns are fixed
(REMITTANCE_COLUMNS,CLAIM_COLUMNS); claim and remittance rows join on
patient_control_number. Composites are split on whatever component
separator the file uses, soHC>99213reads likeHC:99213. A claim paid
without line detail still gets a row. Every 5010 835 and 837 in the test
corpus reads; 4010 files are refused with a reason. -
x12sdk-validate: checking files, with the answer in words. Valid
files are summarised (transactions, implementation, claims); for an invalid
one each problem is located in the loop hierarchy (loop 2000A #1 › loop 2000B #1 › loop 2300 #1: ...) without echoing the file's content. Unreadable
input is explained (a malformed ISA envelope, not X12, file not found). Exits
1 if any file is invalid;--jsonfor machines.x12sdk.validation.check()
from Python; the MCP server'svalidate_x12shares the same formatting. -
x12sdk.matching: remittances joined to claims on the patient control
number.match_claimskeeps every payment for a number (payments,
reversals, corrections) and drops nothing: unanswered claims are
no remittance, payments for claims not given areno claim.
match_rowsgives flat rows. -
scripts/benchmark.pyand published numbers: an 835 reads at about
8,200 claims/s and an 837P at about 2,100 on an Apple-silicon Mac. Memory
grows with the largest transaction: about 540 MB peak for one 837P
transaction of 10,000 claims. -
MCP Registry entry (
server.json, launched with
uvx --from "x12sdk[mcp]==<version>" x12sdk-mcp), and the ownership line
the registry looks for in the README. A test keeps both in step with the
package version.
Changed
- The README opens with common tasks: tables, sample files, checking a file,
AI assistants. - The roadmap promises at least one release a month rather than one fixed
release around the 20th; releases go out when a useful set is ready.
Fixed
- The dataset's service-line table could not be shown on Hugging Face,
and codes lost their leading zeros there. The viewer guessed column types
from the CSVs, took procedure codes for numbers, and failed on the first
dental code; revenue code 0510 read as 510.scripts/build_dataset.pynow
also writes the tables as JSON Lines, where codes are text and amounts
numbers, and the dataset card declares every column's type and points the
viewer at those files. The CSVs and X12 files are unchanged.
x12sdk 2.3.0
Added
- The 837D dental claim (005010X224A2) parses and writes, closing the
read side of #2. It shares the professional claim's envelope and hierarchy;
the claim carries orthodontic months (DN1) and missing or to-be-extracted
teeth (DN2), and each line carries the dental procedure (SV3) with tooth
numbers and surfaces (TOO). Four segments are new to the library: SV3,
TOO, DN1 and DN2. Three synthetic samples join the round-trip sweep: a
subscriber's filling, a child's orthodontic claim, and a tertiary claim
whose crown was adjudicated by two earlier payers. Files declaring
005010X224 or 005010X224A1 read with the same model. generate_837dandx12sdk-generate 837d, completing #2. Lines bill
CDT codes under theADqualifier; a line done to a tooth carries a TOO
segment, with surfaces for a filling, and invented files mix those with
lines that have no tooth (an exam, a cleaning). Both patient branches
appear by default, and one payer is named throughout the file.
ServiceLineSpecgainstoothandsurfaces, validated against the
Universal tooth numbers and the seven surface codes; the 837P and 837I
refuse a tooth rather than dropping it.claims()andsubscribers()on the 837D, the same flattened access
the 837P and 837I have.generate_claim_pair: a claim submission and the remittance that
answers it, from one specification, for the 837P, 837I or 837D. Every
claim is answered by exactly one claim payment, linked by CLM01 = CLP01,
with the same charges, line procedures, patient, payer and payee. Invented
outcomes mix paid in full, contractual write-offs, patient cost share and
outright denials (denial_rate). AClaimSpec's adjustments and status
describe the payer's decision: they reach the 835 and are kept off the
837.build_835gainsprocedure_qualifier,patientsandpayee_npi
so a remittance can answer a particular submission; its output for
existing seeds is unchanged, and a new test pins the README sample to what
the library prints.x12sdk-mcp, an MCP server for AI assistants, behind the optional
mcpextra (pip install "x12sdk[mcp]"). Five read-only tools:
validate_x12(where and why a file fails, without echoing its content),
parse_x12,list_claims(flat rows from an 837, 835, 276 or 277),
generate_x12(any supported set, the same bytes as the library) and
generate_claim_pair. The server works only on the text it is given: the
reader also accepts file paths, and the server refuses them so an assistant
cannot read files off the machine. A bad argument returns its explanation
to the assistant. Built on the MCP Python SDK 2.x.scripts/build_dataset.py, which builds the public synthetic dataset
of claims and remittances: X12 file pairs for the 837P, 837I and 837D with
their 835s, andclaimsandservice_linestables read back out of those
files with the library's own reader, plus a dataset card. The same
arguments rebuild the same bytes. Outcomes are random, and the card says so.
The dataset itself is published at
https://huggingface.co/datasets/owgreen-dev/x12sdk under CC BY 4.0.
Fixed
- A service line adjudicated by more than one payer kept only the last
adjudication in every 837 except the new dental claim: the 837P, the 837I
and both 4010 implementations. The 2430 initializer was guarded by
if TransactionLoops.X:, which is always true, so each SVD reset the list.
A claim sent to a secondary or tertiary payer lost the earlier payers' line
decisions without an error. The audit suite gains a check for guards that
can never be false, which finds exactly these four.
x12sdk 2.2.0
Added
- Provider-level adjustments on generated 835s.
generate_835takes
provider_adjustments: a count to invent,ProviderAdjustmentSpecs to
follow (provider_adjustment("WO", "25.00", "PCN000099")), or the default,
which invents one when the claims are invented and none when they are
specified. Rendered as one PLB segment naming the payee, up to six pairs;
BPR02 is derived as the claim payments less the adjustments, and a
specification that would make it negative is rejected.x12sdk-generate 835 --provider-adjustments N. - Employers and disability periods on generated 834s.
EnrolleeSpectakes
employers(up to threeEmployerSpecs, loop 2100D) anddisabilities
(DisabilitySpecs with type, dates and diagnosis, loop 2200). Invented
rosters give every subscriber an employer, a quarter of them a second, and a
fifth of all members a disability period, so the two repeating loops the
audit suite found mis-parsed in 1.1.0 now have generated coverage. X12ModelWriter, the mirror image ofX12ModelReader: a context manager
that collects transaction models and writes them as one interchange when the
block exits, throughwrite_transactions, so envelopes and control numbers
follow the same rules. The destination is a path, an open text stream, or
nothing (the result stays onwriter.interchange). If the block raises,
nothing is written.write()rejects a non-transaction model at the call,
not at the close.x12sdk-generate, a second console script:x12sdk-generate 835 --seed 7 --claims 2 [--out FILE], one subcommand per transaction set. Every option is
a keyword argument of the matchinggenerate_*function, so the command and
the library call produce the same bytes; the README's opening example is now
a command you can paste. The parsing CLI,x12sdk, is unchanged.- Python 3.14 is tested in CI and declared in the package classifiers. The
suite passes unchanged; nothing in the package needed to move.
Changed
- Invented files differ from 2.1.0 for the same seed. A default 835 now
carries a PLB, a default 834 carries employers and disability periods, and
the payee NPI is drawn earlier, so counts-based output (claims=5,
enrollees=5) is not byte-identical to what 2.1.0 produced. Specified
scenarios are unchanged except where they now ask for the new loops. Pin the
x12sdk version where byte-stable fixtures matter.
pip install --upgrade x12sdk
x12sdk-generate 835 --seed 7 --claims 2
Full changelog: https://github.com/owgreen-dev/x12sdk/blob/main/CHANGELOG.md
x12sdk 2.1.0
pip install x12sdk==2.1.0
Behaviour change
Every hierarchical transaction set now validates HL parent linkage. Each HL segment's parent id must name the HL it is nested under, and ids must be unique. Until now only the 270 and 271 checked this; every 837 implementation and the 276/277 pair accepted a dangling parent in silence, so a file whose hierarchy could not be walked parsed as if it were fine. All 68 HL-bearing corpus samples pass the rule. If you parse partner files with sloppy HL numbering, they will now be rejected, with a message naming the HL and the parent it claims.
All eight transaction sets now generate
generate_837i joins the set. It takes the same specification as generate_837p; what differs is the claim: SV2 revenue-code lines, a facility type, CL1 admission and status, a statement date. The 1.2.0 notes claimed "all eight" prematurely; it is true now.
An audit suite
src/tests/audit/ turns every bug class that has shipped here into a generic detector, run over every transaction set on every commit: structural checks of the models against the parser, construction of every loop and segment from required fields alone, repeat stress through the generators, and mutation of every corpus sample. Backtested against v1.0.0 it flags every defect found by hand this year, by name. On its way in it found six more, fixed in this release. repo-docs/AUDIT.md describes it, limits included.
Also fixed
Three more repeating loops that kept only their last occurrence; an unguarded 4010 handler that made a class of coordination-of-benefits claim unparseable; HiSegment validating nothing inside its composites; HSD rejecting a valid segment; a 4010 ISA that validated but could not be rendered.
2051 tests on Python 3.10 through 3.13. Corpus 95 files, every one round-tripped byte for byte.
x12sdk 2.0.0
pip install x12sdk==2.0.0
Fixes silent data loss on two repeating loops. A 270 was keeping only the last eligibility question asked.
What was wrong
Loop 2110 on a 270 repeats up to 99 times, so one inquiry may ask about several service types. The parser assigned a fresh loop on every EQ instead of appending, and the model held a single loop where the 271 correctly holds a list:
EQ*30~ medical
EQ*35~ dental
EQ*88~ vision <- only this one survived
No error was raised. The other two were simply gone. A provider asking one payer about several coverages in a single transaction is ordinary use.
A sweep of every parser afterwards found a second instance: an 834 kept only the last disability period. That field was already declared a list, so a single period looked correct because a lone record gets wrapped, which hid the defect entirely. No sample in the inherited corpus carries a disability segment at all.
Breaking change
Two fields on the 270 became lists. Reading code that walked them directly must index or iterate now. Nothing else in the public interface changed.
| field | before | after |
|---|---|---|
Loop2100C.loop_2110c |
Optional[Loop2110C] |
Optional[List[Loop2110C]] |
Loop2100D.loop_2110d |
Loop2110D (required) |
List[Loop2110D] (required) |
# before
...loop_2100c.loop_2110c.eq_segment
# after
...loop_2100c.loop_2110c[0].eq_segmentThe 271 already held lists here, so the two halves of the eligibility pair now agree.
If you use members() you need no change. The accessor already normalised a single loop and a list to the same tuple. Writers are unaffected: constructing a loop with one benefit still works either way.
Also in this release
generate_270 now renders every benefit in a specification. It previously refused more than one, because the defect above made a second inquiry unrepresentable.
Two samples join the corpus for the repaired loops, both in the byte-for-byte round-trip sweep permanently: a 270 asking about several service types across both the subscriber and dependent branches, and an 834 with two disability periods. 87 files to 89.
757 tests on Python 3.10 through 3.13.
Note on 1.2.0
The 1.2.0 notes claimed every supported transaction set could be generated. That was wrong: seven of the eight generate, and the institutional claim 837I has none yet. A PyPI description cannot be edited after upload, so the 1.2.0 page still carries the original wording. This release replaces it on the project page.
x12sdk 1.2.0
pip install x12sdk==1.2.0
Correction, added after publishing: the line below originally read "every supported transaction set". That was wrong — seven of the eight generate. The institutional claim, 837I, is parsed and has accessors but has no generator yet. The PyPI description for 1.2.0 cannot be edited after upload, so it still carries the original wording.
Seven of the eight supported transaction sets can now be generated, and every set that branches on subscriber versus dependent has an accessor that hides it.
| set | generator | accessor |
|---|---|---|
| 835 | generate_835 |
claims() |
| 837P | generate_837p |
claims(), subscribers() |
| 837I | none yet | claims(), subscribers() |
| 270 / 271 | generate_270 / generate_271 |
members() |
| 276 / 277 | generate_276 / generate_277 |
claims() |
| 834 | generate_834 |
no hierarchy to hide |
Why this matters
Real claims, remittances and eligibility files contain PHI, and there is no public X12 corpus. Anyone testing an X12 pipeline has nowhere to get files. Now:
from x12sdk.generate import generate_271, generate_276
response = generate_271(seed=7, members=25)
inquiry = generate_276(seed=7, patients=25)The same seed reproduces the same bytes, and generation never touches the global random state, so it is safe inside someone else's test suite.
The branch that loses data
In an 837, a 270, a 271, a 276 and a 277, a patient sits at one of two depths: under the subscriber when the patient is the subscriber, and under a dependent when they are not. Code written against one path runs without error on a file that uses the other and reports nothing. Nothing raises; the count is just wrong.
Generated files contain both branches by default, so the trap is testable. The accessors walk both, so it stops being a trap:
for member in eligibility.members():
print(member.name, member.is_dependent, member.service_type_codes)Inquiry and response pairs are generated from one specification and stay in step on a seed, so a 270 and the 271 answering it describe the same people.
Three defects fixed
None is reachable by parsing, which is why the inherited corpus never caught any of them.
validate_hierarchy_idsmade a second subscriber impossible on a 270 or 271. It required every HL segment to be parented by the previous HL in the file, which is not an X12 rule and contradicts the check beside it. A provider checking eligibility for a list of patients is the ordinary use of a 270._validate_duplicate_codescrashed on any constructed loop without REF. It read a key that is always present and set toNoneusing aget()default. This is shared code, so it affected every transaction set using the duplicate-REF or duplicate-AMT checks.- The 834 alone had its segment-count check commented out, so it was the one transaction set that accepted a wrong SE01 in silence.
Behaviour change
The 834 now validates SE01, like the other seven sets always have. All ten inherited samples were verified correct before enabling it, so nothing in the corpus changes. If you parse 834 files from a partner who miscounts SE01, they will now be rejected rather than parsed.
Full detail in CHANGELOG.md.
750 tests on Python 3.10 through 3.13, 96% coverage. Sample corpus 72 files to 87, every one round-tripped byte for byte.