@claritylabs/cl-sdk 3.1.3 → 3.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -546,6 +546,13 @@ var PET_SPECIES = PetSpeciesSchema.options;
546
546
 
547
547
  // src/schemas/shared.ts
548
548
  import { z as z3 } from "zod";
549
+ var SourceProvenanceSchema = z3.object({
550
+ sourceSpanIds: z3.array(z3.string().min(1)).min(1),
551
+ documentNodeId: z3.string().optional(),
552
+ sourceTextHash: z3.string().optional(),
553
+ pageStart: z3.number().int().positive().optional(),
554
+ pageEnd: z3.number().int().positive().optional()
555
+ });
549
556
  var AddressSchema = z3.object({
550
557
  street1: z3.string(),
551
558
  street2: z3.string().optional(),
@@ -554,6 +561,7 @@ var AddressSchema = z3.object({
554
561
  zip: z3.string(),
555
562
  country: z3.string().optional()
556
563
  });
564
+ var SourceBackedAddressSchema = AddressSchema.merge(SourceProvenanceSchema);
557
565
  var ContactSchema = z3.object({
558
566
  name: z3.string().optional(),
559
567
  title: z3.string().optional(),
@@ -563,7 +571,7 @@ var ContactSchema = z3.object({
563
571
  email: z3.string().optional(),
564
572
  address: AddressSchema.optional(),
565
573
  hours: z3.string().optional()
566
- });
574
+ }).merge(SourceProvenanceSchema);
567
575
  var FormReferenceSchema = z3.object({
568
576
  formNumber: z3.string(),
569
577
  editionDate: z3.string().optional(),
@@ -610,7 +618,7 @@ var NamedInsuredSchema = z3.object({
610
618
  name: z3.string(),
611
619
  relationship: z3.string().optional(),
612
620
  address: AddressSchema.optional()
613
- });
621
+ }).merge(SourceProvenanceSchema);
614
622
 
615
623
  // src/schemas/coverage.ts
616
624
  import { z as z4 } from "zod";
@@ -682,7 +690,7 @@ var EndorsementPartySchema = z5.object({
682
690
  address: AddressSchema.optional(),
683
691
  relationship: z5.string().optional(),
684
692
  scope: z5.string().optional()
685
- });
693
+ }).merge(SourceProvenanceSchema);
686
694
  var EndorsementSchema = z5.object({
687
695
  formNumber: z5.string(),
688
696
  editionDate: z5.string().optional(),
@@ -749,7 +757,7 @@ var InsurerInfoSchema = z8.object({
749
757
  amBestNumber: z8.string().optional(),
750
758
  admittedStatus: AdmittedStatusSchema.optional(),
751
759
  stateOfDomicile: z8.string().optional()
752
- });
760
+ }).merge(SourceProvenanceSchema);
753
761
  var ProducerInfoSchema = z8.object({
754
762
  agencyName: z8.string(),
755
763
  contactName: z8.string().optional(),
@@ -757,7 +765,7 @@ var ProducerInfoSchema = z8.object({
757
765
  phone: z8.string().optional(),
758
766
  email: z8.string().optional(),
759
767
  address: AddressSchema.optional()
760
- });
768
+ }).merge(SourceProvenanceSchema);
761
769
 
762
770
  // src/schemas/financial.ts
763
771
  import { z as z9 } from "zod";
@@ -1468,7 +1476,7 @@ var BaseDocumentFields = {
1468
1476
  isRenewal: z16.boolean().optional(),
1469
1477
  isPackage: z16.boolean().optional(),
1470
1478
  insuredDba: z16.string().optional(),
1471
- insuredAddress: AddressSchema.optional(),
1479
+ insuredAddress: SourceBackedAddressSchema.optional(),
1472
1480
  insuredEntityType: EntityTypeSchema.optional(),
1473
1481
  additionalNamedInsureds: z16.array(NamedInsuredSchema).optional(),
1474
1482
  insuredSicCode: z16.string().optional(),
@@ -4649,6 +4657,17 @@ function getCoveredReasons(memory) {
4649
4657
  }
4650
4658
 
4651
4659
  // src/extraction/promote.ts
4660
+ function sourceProvenance(raw) {
4661
+ const sourceSpanIds = Array.isArray(raw.sourceSpanIds) ? raw.sourceSpanIds.filter((id) => typeof id === "string" && id.trim().length > 0) : [];
4662
+ if (sourceSpanIds.length === 0) return void 0;
4663
+ return {
4664
+ sourceSpanIds,
4665
+ ...typeof raw.documentNodeId === "string" ? { documentNodeId: raw.documentNodeId } : {},
4666
+ ...typeof raw.sourceTextHash === "string" ? { sourceTextHash: raw.sourceTextHash } : {},
4667
+ ...typeof raw.pageStart === "number" ? { pageStart: raw.pageStart } : {},
4668
+ ...typeof raw.pageEnd === "number" ? { pageEnd: raw.pageEnd } : {}
4669
+ };
4670
+ }
4652
4671
  function stringValue(value) {
4653
4672
  return typeof value === "string" && value.trim() ? value : void 0;
4654
4673
  }
@@ -4669,36 +4688,38 @@ function promoteRawFields(raw, mappings) {
4669
4688
  }
4670
4689
  function promoteCarrierFields(doc) {
4671
4690
  const raw = doc;
4691
+ const provenance = sourceProvenance(raw);
4672
4692
  promoteRawFields(raw, [
4673
4693
  { from: "naicNumber", to: "carrierNaicNumber" },
4674
4694
  { from: "amBestRating", to: "carrierAmBestRating" },
4675
4695
  { from: "admittedStatus", to: "carrierAdmittedStatus" }
4676
4696
  ]);
4677
- if (!raw.insurer && raw.carrierLegalName) {
4697
+ if (!raw.insurer && raw.carrierLegalName && provenance) {
4678
4698
  raw.insurer = {
4679
4699
  legalName: raw.carrierLegalName,
4680
4700
  ...raw.carrierNaicNumber ? { naicNumber: raw.carrierNaicNumber } : {},
4681
4701
  ...raw.carrierAmBestRating ? { amBestRating: raw.carrierAmBestRating } : {},
4682
- ...raw.carrierAdmittedStatus ? { admittedStatus: raw.carrierAdmittedStatus } : {}
4702
+ ...raw.carrierAdmittedStatus ? { admittedStatus: raw.carrierAdmittedStatus } : {},
4703
+ ...provenance
4683
4704
  };
4684
4705
  }
4685
4706
  }
4686
4707
  function promoteBroker(doc) {
4687
4708
  const raw = doc;
4709
+ const provenance = sourceProvenance(raw);
4688
4710
  const brokerAgency = findRawString(raw, ["brokerAgency"]);
4689
4711
  const brokerContact = findRawString(raw, ["brokerContactName"]);
4690
4712
  const brokerLicense = findRawString(raw, ["brokerLicenseNumber"]);
4691
4713
  const brokerPhone = findRawString(raw, ["brokerPhone"]);
4692
4714
  const brokerEmail = findRawString(raw, ["brokerEmail"]);
4693
- const brokerAddress = findRawString(raw, ["brokerAddress"]);
4694
- if (!raw.producer && brokerAgency) {
4715
+ if (!raw.producer && brokerAgency && provenance) {
4695
4716
  raw.producer = {
4696
4717
  agencyName: brokerAgency,
4697
4718
  ...brokerContact ? { contactName: brokerContact } : {},
4698
4719
  ...brokerLicense ? { licenseNumber: brokerLicense } : {},
4699
4720
  ...brokerPhone ? { phone: brokerPhone } : {},
4700
4721
  ...brokerEmail ? { email: brokerEmail } : {},
4701
- ...brokerAddress ? { address: { street1: brokerAddress } } : {}
4722
+ ...provenance
4702
4723
  };
4703
4724
  }
4704
4725
  }
@@ -7652,16 +7673,19 @@ Return JSON only.`;
7652
7673
 
7653
7674
  // src/prompts/extractors/named-insured.ts
7654
7675
  import { z as z27 } from "zod";
7655
- var AddressSchema2 = z27.object({
7656
- street1: z27.string(),
7657
- city: z27.string(),
7658
- state: z27.string(),
7659
- zip: z27.string()
7660
- });
7676
+ var AdditionalNamedInsuredSchema = z27.object({
7677
+ name: z27.string(),
7678
+ relationship: z27.string().optional().describe("e.g. subsidiary, affiliate"),
7679
+ address: SourceBackedAddressSchema.optional()
7680
+ }).merge(SourceProvenanceSchema);
7681
+ var ScheduledPartySchema = z27.object({
7682
+ name: z27.string(),
7683
+ address: SourceBackedAddressSchema.optional()
7684
+ }).merge(SourceProvenanceSchema);
7661
7685
  var NamedInsuredSchema2 = z27.object({
7662
7686
  insuredName: z27.string().describe("Name of primary named insured"),
7663
7687
  insuredDba: z27.string().optional().describe("Doing-business-as name"),
7664
- insuredAddress: AddressSchema2.optional().describe("Primary insured mailing address"),
7688
+ insuredAddress: SourceBackedAddressSchema.optional().describe("Primary insured mailing address"),
7665
7689
  insuredEntityType: z27.enum([
7666
7690
  "corporation",
7667
7691
  "llc",
@@ -7678,25 +7702,9 @@ var NamedInsuredSchema2 = z27.object({
7678
7702
  insuredFein: z27.string().optional().describe("Federal Employer Identification Number"),
7679
7703
  insuredSicCode: z27.string().optional().describe("SIC code"),
7680
7704
  insuredNaicsCode: z27.string().optional().describe("NAICS code"),
7681
- additionalNamedInsureds: z27.array(
7682
- z27.object({
7683
- name: z27.string(),
7684
- relationship: z27.string().optional().describe("e.g. subsidiary, affiliate"),
7685
- address: AddressSchema2.optional()
7686
- })
7687
- ).optional().describe("Additional named insureds listed on the policy"),
7688
- lossPayees: z27.array(
7689
- z27.object({
7690
- name: z27.string(),
7691
- address: AddressSchema2.optional()
7692
- })
7693
- ).optional().describe("Loss payees listed on the policy"),
7694
- mortgageHolders: z27.array(
7695
- z27.object({
7696
- name: z27.string(),
7697
- address: AddressSchema2.optional()
7698
- })
7699
- ).optional().describe("Mortgage holders / lienholders listed on the policy")
7705
+ additionalNamedInsureds: z27.array(AdditionalNamedInsuredSchema).optional().describe("Additional named insureds listed on the policy"),
7706
+ lossPayees: z27.array(ScheduledPartySchema).optional().describe("Loss payees listed on the policy"),
7707
+ mortgageHolders: z27.array(ScheduledPartySchema).optional().describe("Mortgage holders / lienholders listed on the policy")
7700
7708
  });
7701
7709
  function buildNamedInsuredPrompt() {
7702
7710
  return `You are an expert insurance document analyst. Extract all named insured information from this document.
@@ -7713,6 +7721,7 @@ Focus on:
7713
7721
  Look on the declarations page, named insured schedule, loss payee schedule, mortgagee schedule, and any endorsements that add or modify named insureds, loss payees, or mortgage holders.
7714
7722
 
7715
7723
  Critical rules:
7724
+ - Every insuredAddress, additionalNamedInsureds row, lossPayees row, and mortgageHolders row must include sourceSpanIds from the source evidence. Omit the row if source spans are unavailable.
7716
7725
  - Prefer declaration-table labels such as "Named Insured", "Named Insured and Address", "Applicant", or "Insured" over contact blocks, notice contacts, authorized officers, licensing statements, signatures, and corporate-authority wording.
7717
7726
  - Do not use an authorized officer, broker, producer, contact person, officer title, email address owner, or licensing/entity-status statement as the primary insured unless that exact person/entity is explicitly labeled as the named insured.
7718
7727
  - If a row combines the insured name with a mailing address, put the legal name in insuredName and the mailing address in insuredAddress.
@@ -8176,13 +8185,6 @@ Return JSON only.`;
8176
8185
 
8177
8186
  // src/prompts/extractors/supplementary.ts
8178
8187
  import { z as z36 } from "zod";
8179
- var ContactSchema2 = z36.object({
8180
- name: z36.string().optional().describe("Organization or person name"),
8181
- phone: z36.string().optional().describe("Phone number"),
8182
- email: z36.string().optional().describe("Email address"),
8183
- address: z36.string().optional().describe("Mailing address"),
8184
- type: z36.string().optional().describe("Contact type, e.g. 'State Department of Insurance'")
8185
- });
8186
8188
  var AuxiliaryFactSchema2 = z36.object({
8187
8189
  key: z36.string().describe("Normalized machine-readable fact key, e.g. 'policyholder_age' or 'insured_name'"),
8188
8190
  value: z36.string().describe("Concrete extracted fact value"),
@@ -8190,9 +8192,9 @@ var AuxiliaryFactSchema2 = z36.object({
8190
8192
  context: z36.string().optional().describe("Short disambiguating context, such as 'Driver Schedule' or 'Named Insured'")
8191
8193
  });
8192
8194
  var SupplementarySchema = z36.object({
8193
- regulatoryContacts: z36.array(ContactSchema2).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
8194
- claimsContacts: z36.array(ContactSchema2).optional().describe("Claims reporting contacts and instructions"),
8195
- thirdPartyAdministrators: z36.array(ContactSchema2).optional().describe("Third-party administrators for claims handling"),
8195
+ regulatoryContacts: z36.array(ContactSchema).optional().describe("Regulatory body contacts (state department of insurance, ombudsman)"),
8196
+ claimsContacts: z36.array(ContactSchema).optional().describe("Claims reporting contacts and instructions"),
8197
+ thirdPartyAdministrators: z36.array(ContactSchema).optional().describe("Third-party administrators for claims handling"),
8196
8198
  cancellationNoticeDays: z36.number().optional().describe("Required notice period for cancellation in days"),
8197
8199
  nonrenewalNoticeDays: z36.number().optional().describe("Required notice period for nonrenewal in days"),
8198
8200
  auxiliaryFacts: z36.array(AuxiliaryFactSchema2).optional().describe("Additional retrieval-only facts that do not fit the strict primary schema")
@@ -8207,7 +8209,7 @@ ${alreadyExtractedSummary}
8207
8209
  return `You are an expert insurance document analyst. Extract supplementary, retrieval-only information from this document that is NOT already captured in the structured extraction results.
8208
8210
  ${exclusionBlock}
8209
8211
  Focus on:
8210
- - Regulatory contacts: state department of insurance, regulatory bodies, ombudsman offices \u2014 with phone, email, address
8212
+ - Regulatory contacts: state department of insurance, regulatory bodies, ombudsman offices \u2014 with phone, email, structured address
8211
8213
  - Claims contacts: how to report claims, claims department contact info, hours of operation
8212
8214
  - Third-party administrators (TPAs) for claims handling
8213
8215
  - Cancellation notice period in days
@@ -8218,6 +8220,8 @@ Focus on:
8218
8220
 
8219
8221
  Look for regulatory notices, complaint contact sections, claims reporting instructions, and cancellation/nonrenewal provisions throughout the document.
8220
8222
 
8223
+ Every regulatoryContacts, claimsContacts, and thirdPartyAdministrators row must include sourceSpanIds from the source evidence. Omit contacts when source spans are unavailable.
8224
+
8221
8225
  For auxiliaryFacts:
8222
8226
  - ONLY capture facts that are NOT already present in the structured extraction results above.
8223
8227
  - Do not duplicate information that has already been extracted \u2014 no policy numbers, insured names, addresses, coverage limits, deductibles, or any other field that appears in the already-extracted data.
@@ -11432,6 +11436,13 @@ function valueOf(profile, key) {
11432
11436
  }
11433
11437
  return String(value.value);
11434
11438
  }
11439
+ function provenanceOf(value) {
11440
+ if (!value?.sourceSpanIds.length) return void 0;
11441
+ return {
11442
+ sourceSpanIds: value.sourceSpanIds,
11443
+ ...value.sourceNodeIds[0] ? { documentNodeId: value.sourceNodeIds[0] } : {}
11444
+ };
11445
+ }
11435
11446
  function materializeDocument(params) {
11436
11447
  const profile = params.operationalProfile;
11437
11448
  const policyNumber = valueOf(profile, "policyNumber") ?? "Unknown";
@@ -11440,6 +11451,9 @@ function materializeDocument(params) {
11440
11451
  const effectiveDate = valueOf(profile, "effectiveDate") ?? "Unknown";
11441
11452
  const expirationDate = valueOf(profile, "expirationDate") ?? "Unknown";
11442
11453
  const premium = valueOf(profile, "premium");
11454
+ const insurerProvenance = provenanceOf(profile.insurer);
11455
+ const broker = valueOf(profile, "broker");
11456
+ const brokerProvenance = provenanceOf(profile.broker);
11443
11457
  const coverages = profile.coverages.map((coverage) => ({
11444
11458
  name: coverage.name,
11445
11459
  coverageCode: coverage.coverageCode,
@@ -11491,6 +11505,11 @@ function materializeDocument(params) {
11491
11505
  security: carrier,
11492
11506
  insuredName,
11493
11507
  premium,
11508
+ ...insurerProvenance ? { insurer: { legalName: carrier, ...insurerProvenance } } : {},
11509
+ ...broker && brokerProvenance ? {
11510
+ brokerAgency: broker,
11511
+ producer: { agencyName: broker, ...brokerProvenance }
11512
+ } : {},
11494
11513
  policyTypes: profile.policyTypes,
11495
11514
  formInventory: params.formInventory.filter((form) => typeof form.formNumber === "string" && form.formNumber.trim().length > 0).map((form) => ({
11496
11515
  formNumber: form.formNumber,
@@ -17173,9 +17192,11 @@ export {
17173
17192
  ScheduledItemCategorySchema,
17174
17193
  SectionSchema,
17175
17194
  SharedLimitSchema,
17195
+ SourceBackedAddressSchema,
17176
17196
  SourceBackedValueSchema,
17177
17197
  SourceChunkSchema,
17178
17198
  SourceKindSchema,
17199
+ SourceProvenanceSchema,
17179
17200
  SourceSpanBBoxSchema,
17180
17201
  SourceSpanKindSchema,
17181
17202
  SourceSpanLocationSchema,