Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sputhenofficial/claimjumper/llms.txt
Use this file to discover all available pages before exploring further.
draft() in lib/pipeline/draft.ts accepts a DraftInput (full parsed claim + service line + triage decision) and a model client, then produces a DraftArtifact. For appeal and corrected_claim lanes it calls GPT-5.6 Terra and then validates every citation in the response before the artifact is returned. For human_review it generates a deterministic plain-text brief without any model call. For patient_bill and write_off it throws immediately — those lanes never receive drafted artifacts and the route handler catches that error gracefully.
Function signature
DraftModelClient is a type alias for the exact shape of responseWithTextSchema from lib/openai.ts:
DraftModelOutput can substitute for the live OpenAI call.
adaptForDrafting()
The route handler uses adaptForDrafting() to assemble a DraftInput from the three sources it has in scope. This join helper parses the assembled object through DraftInputSchema, catching any structural problem before it reaches the model:
DraftInput intentionally carries the full ClaimSchema object rather than the leaner AdjustmentLine used in triage. Draft citations reference nested fields such as claim.remittance.code_legend and claim.claim.claim_id, which are not present in the adjustment-line projection.
validateCitations()
draft() calls validateCitations() on every citation in the output before constructing the DraftArtifact. A citation carries a source ("parse" or "legend"), a field_path, and a value. Validation resolves each citation against the original DraftInput and checks that the resolved value matches the cited string exactly.
Parse citations — field_path is a dotted property path from the DraftInput root (e.g. claim.claim.claim_id or service_line.group_code). The resolver walks the path using Object.hasOwn checks for objects and numeric index parsing for arrays.
Legend citations — field_path follows the pattern CODE_SYSTEM:CODE.field (e.g. CARC:50.definition or RARC:N115.definition). The resolver locates the matching entry in claim.remittance.code_legend by code_system and code, then reads the named field.
If a path does not resolve, or if the resolved value does not match citation.value exactly (as a string), validateCitations() throws an error. This prevents the artifact from being returned to the caller, ensuring that every factual claim in a draft can be traced back to a verified remittance field.
validateArtifact()
After citations are verified, draft() calls validateArtifact(), which enforces three content safety rules on the draft body:
Prohibited submission phrases — a regex match for language that implies automated action. Phrases such as "we have submitted", "this appeal has been filed", and "approved" are blocked because they misrepresent the draft’s status as a human-review work product.
appeal and corrected_claim drafts, the group code, CARC, and RARC (when present) must each appear literally in the body text. A draft that omits the denial codes that drove the routing is considered incomplete.
CARC 50 medical necessity assertion prohibition — for appeal drafts where carc === "50", the body may not make any of the following assertions:
Human-review brief
When the lane ishuman_review, draft() calls the internal reviewBrief() function instead of the model. reviewBrief() builds a deterministic plain-text brief from the claim, service line, and triage result — no model call, no citations to validate:
reviewBrief() still runs validateArtifact() on the generated content to ensure no prohibited phrase was accidentally introduced by a triage rationale or evidence string. The resulting DraftArtifact has citations: [] and a lane of "human_review". It cannot be approved or exported by the UI.
Prompt design
The draft prompt atprompts/draft.md gives the model a focused lane-specific drafting role with strict grounding constraints. The key lane rules:
appealwith CARC 29 — referenceservice_date,claim_received_date, and the clearinghouse-acknowledgment date innotes. Request review of timely filing.appealwith CARC 50 and RARC N115 — make a procedural request only. Quote the supplied CARC and RARC definitions. Ask the payer to identify the specific LCD and criterion. Do not assert medical necessity, any patient condition, or that any criterion was met.corrected_claimwith CARC 16 and RARC M51 — produce a worklist naming the exact fields to correct. Do not use appeal language.
citation.value matching the source field’s canonical string value exactly. The grounding constraints are: