@claritylabs/cl-sdk 0.7.3 → 0.7.5

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
@@ -92,29 +92,40 @@ function toStrictSchema(schema) {
92
92
  const fieldType = fieldDef?.type ?? field.type;
93
93
  if (fieldType === "optional") {
94
94
  const innerType = fieldDef?.innerType;
95
+ const description = field.description ?? fieldDef?.description ?? field._zod?.def?.description;
95
96
  if (innerType) {
96
97
  const transformed = toStrictSchema(innerType);
97
- newShape[key] = z.nullable(transformed);
98
+ let nullable = z.nullable(transformed);
99
+ if (description) nullable = nullable.describe(description);
100
+ newShape[key] = nullable;
98
101
  } else {
99
- newShape[key] = z.nullable(field);
102
+ let nullable = z.nullable(field);
103
+ if (description) nullable = nullable.describe(description);
104
+ newShape[key] = nullable;
100
105
  }
101
106
  } else {
102
107
  newShape[key] = toStrictSchema(field);
103
108
  }
104
109
  }
105
- return z.object(newShape);
110
+ const objDesc = schema.description ?? def?.description ?? schema._zod?.def?.description;
111
+ const result = z.object(newShape);
112
+ return objDesc ? result.describe(objDesc) : result;
106
113
  }
107
114
  if (typeName === "array") {
108
115
  const element = def?.element ?? schema.element;
109
116
  if (element) {
110
- return z.array(toStrictSchema(element));
117
+ const arrDesc = schema.description ?? def?.description ?? schema._zod?.def?.description;
118
+ const result = z.array(toStrictSchema(element));
119
+ return arrDesc ? result.describe(arrDesc) : result;
111
120
  }
112
121
  return schema;
113
122
  }
114
123
  if (typeName === "nullable") {
115
124
  const innerType = def?.innerType;
116
125
  if (innerType) {
117
- return z.nullable(toStrictSchema(innerType));
126
+ const nullDesc = schema.description ?? def?.description ?? schema._zod?.def?.description;
127
+ const result = z.nullable(toStrictSchema(innerType));
128
+ return nullDesc ? result.describe(nullDesc) : result;
118
129
  }
119
130
  return schema;
120
131
  }
@@ -2605,29 +2616,73 @@ function getTemplate(policyType) {
2605
2616
  // src/prompts/coordinator/classify.ts
2606
2617
  import { z as z18 } from "zod";
2607
2618
  var ClassifyResultSchema = z18.object({
2608
- documentType: z18.enum(["policy", "quote"]),
2609
- policyTypes: z18.array(PolicyTypeSchema),
2610
- confidence: z18.number()
2619
+ documentType: z18.enum(["policy", "quote"]).describe("Whether this is a bound policy or a proposed quote"),
2620
+ policyTypes: z18.array(PolicyTypeSchema).min(1).describe("Lines of business covered \u2014 at least one required"),
2621
+ confidence: z18.number().describe("Confidence score from 0.0 to 1.0")
2611
2622
  });
2612
2623
  function buildClassifyPrompt() {
2613
- return `You are classifying an insurance document. Examine the first few pages and determine:
2624
+ return `You are classifying an insurance document. Examine the document and determine:
2614
2625
 
2615
2626
  1. Whether this is a POLICY (bound coverage) or QUOTE (proposed coverage)
2616
- 2. What lines of business are covered
2617
-
2618
- Policies typically have: policy numbers, effective/expiration dates, declarations pages, premium charges.
2619
- Quotes typically have: quote numbers, proposed dates, subjectivities, "indication" or "proposal" language.
2620
-
2621
- Return JSON matching this structure:
2627
+ 2. What lines of business are covered (at least one \u2014 never return an empty list)
2628
+
2629
+ POLICY indicators: policy numbers, effective/expiration dates, declarations pages, premium charges, "this policy" language.
2630
+ QUOTE indicators: quote numbers, proposed dates, subjectivities, "indication" or "proposal" language, "quoted premium".
2631
+
2632
+ COMMERCIAL LINES \u2014 match these values:
2633
+ - "general_liability" \u2014 CGL, commercial general liability, GL
2634
+ - "commercial_property" \u2014 commercial property, building/contents coverage
2635
+ - "commercial_auto" \u2014 commercial auto, business auto, CA
2636
+ - "non_owned_auto" \u2014 hired & non-owned auto
2637
+ - "workers_comp" \u2014 workers compensation, WC
2638
+ - "umbrella" \u2014 commercial umbrella
2639
+ - "excess_liability" \u2014 excess liability, follow-form excess
2640
+ - "professional_liability" \u2014 E&O, errors & omissions, professional liability, malpractice
2641
+ - "cyber" \u2014 cyber liability, data breach, network security
2642
+ - "epli" \u2014 employment practices liability
2643
+ - "directors_officers" \u2014 D&O, directors and officers
2644
+ - "fiduciary_liability" \u2014 fiduciary liability
2645
+ - "crime_fidelity" \u2014 crime, fidelity, employee dishonesty
2646
+ - "inland_marine" \u2014 inland marine, equipment floater, contractors equipment
2647
+ - "builders_risk" \u2014 builders risk, course of construction
2648
+ - "environmental" \u2014 environmental, pollution liability
2649
+ - "ocean_marine" \u2014 ocean marine, cargo, hull
2650
+ - "surety" \u2014 surety bond
2651
+ - "product_liability" \u2014 product liability, products-completed operations
2652
+ - "bop" \u2014 business owners policy, BOP
2653
+ - "management_liability_package" \u2014 management liability package
2654
+ - "property" \u2014 standalone property
2655
+
2656
+ PERSONAL LINES \u2014 match these values:
2657
+ - "homeowners_ho3" \u2014 HO-3, special form homeowners
2658
+ - "homeowners_ho5" \u2014 HO-5, comprehensive form homeowners
2659
+ - "renters_ho4" \u2014 HO-4, renters insurance
2660
+ - "condo_ho6" \u2014 HO-6, condo unit-owners
2661
+ - "dwelling_fire" \u2014 DP-1, DP-3, dwelling fire
2662
+ - "mobile_home" \u2014 mobile home, manufactured home
2663
+ - "personal_auto" \u2014 personal auto, PAP
2664
+ - "personal_umbrella" \u2014 personal umbrella
2665
+ - "flood_nfip" \u2014 NFIP flood
2666
+ - "flood_private" \u2014 private flood
2667
+ - "earthquake" \u2014 earthquake
2668
+ - "personal_inland_marine" \u2014 personal articles, scheduled personal property
2669
+ - "watercraft" \u2014 watercraft, boat
2670
+ - "recreational_vehicle" \u2014 RV, recreational vehicle, ATV
2671
+ - "farm_ranch" \u2014 farm, ranch
2672
+ - "pet" \u2014 pet insurance
2673
+ - "travel" \u2014 travel insurance
2674
+ - "identity_theft" \u2014 identity theft
2675
+ - "title" \u2014 title insurance
2676
+ - "other" \u2014 only if NONE of the above match
2677
+
2678
+ IMPORTANT: You must identify at least one specific policy type. Only use "other" as a last resort when the document truly does not match any known type.
2679
+
2680
+ Return JSON only:
2622
2681
  {
2623
2682
  "documentType": "policy" | "quote",
2624
- "policyTypes": ["general_liability", "commercial_property", ...],
2683
+ "policyTypes": ["general_liability", ...],
2625
2684
  "confidence": 0.0-1.0
2626
- }
2627
-
2628
- Use these policy type values: general_liability, commercial_property, commercial_auto, non_owned_auto, workers_comp, umbrella, excess_liability, professional_liability, cyber, epli, directors_officers, fiduciary_liability, crime_fidelity, inland_marine, builders_risk, environmental, ocean_marine, surety, product_liability, bop, management_liability_package, property, homeowners_ho3, homeowners_ho5, renters_ho4, condo_ho6, dwelling_fire, mobile_home, personal_auto, personal_umbrella, flood_nfip, flood_private, earthquake, personal_inland_marine, watercraft, recreational_vehicle, farm_ranch, pet, travel, identity_theft, title, other.
2629
-
2630
- Respond with JSON only.`;
2685
+ }`;
2631
2686
  }
2632
2687
 
2633
2688
  // src/prompts/coordinator/plan.ts
@@ -2846,27 +2901,71 @@ import { z as z24 } from "zod";
2846
2901
  var EndorsementsSchema = z24.object({
2847
2902
  endorsements: z24.array(
2848
2903
  z24.object({
2849
- formNumber: z24.string().optional().describe("Form number, e.g. 'CG 21 47'"),
2850
- title: z24.string().optional().describe("Endorsement title"),
2851
- type: z24.enum(["broadening", "restrictive", "informational"]).optional().describe("Effect type: broadening adds coverage, restrictive limits it"),
2852
- content: z24.string().optional().describe("Full verbatim text of the endorsement"),
2904
+ formNumber: z24.string().describe("Form number, e.g. 'CG 21 47'"),
2905
+ editionDate: z24.string().optional().describe("Edition date, e.g. '12 07'"),
2906
+ title: z24.string().describe("Endorsement title"),
2907
+ endorsementType: z24.enum([
2908
+ "additional_insured",
2909
+ "waiver_of_subrogation",
2910
+ "primary_noncontributory",
2911
+ "blanket_additional_insured",
2912
+ "loss_payee",
2913
+ "mortgage_holder",
2914
+ "broadening",
2915
+ "restriction",
2916
+ "exclusion",
2917
+ "amendatory",
2918
+ "notice_of_cancellation",
2919
+ "designated_premises",
2920
+ "classification_change",
2921
+ "schedule_update",
2922
+ "deductible_change",
2923
+ "limit_change",
2924
+ "territorial_extension",
2925
+ "other"
2926
+ ]).describe("Endorsement type classification"),
2853
2927
  effectiveDate: z24.string().optional().describe("Endorsement effective date"),
2854
- premium: z24.string().optional().describe("Additional premium or credit"),
2855
- parties: z24.array(z24.string()).optional().describe("Named parties (additional insureds, loss payees, etc.)")
2928
+ affectedCoverageParts: z24.array(z24.string()).optional().describe("Coverage parts affected by this endorsement"),
2929
+ namedParties: z24.array(
2930
+ z24.object({
2931
+ name: z24.string().describe("Party name"),
2932
+ role: z24.enum([
2933
+ "additional_insured",
2934
+ "loss_payee",
2935
+ "mortgage_holder",
2936
+ "certificate_holder",
2937
+ "waiver_beneficiary",
2938
+ "designated_person",
2939
+ "other"
2940
+ ]).describe("Party role"),
2941
+ relationship: z24.string().optional().describe("Relationship to insured"),
2942
+ scope: z24.string().optional().describe("Scope of coverage for this party")
2943
+ })
2944
+ ).optional().describe("Named parties (additional insureds, loss payees, etc.)"),
2945
+ keyTerms: z24.array(z24.string()).optional().describe("Key terms or notable provisions in the endorsement"),
2946
+ premiumImpact: z24.string().optional().describe("Additional premium or credit"),
2947
+ content: z24.string().describe("Full verbatim text of the endorsement"),
2948
+ pageStart: z24.number().describe("Starting page number of this endorsement"),
2949
+ pageEnd: z24.number().optional().describe("Ending page number of this endorsement")
2856
2950
  })
2857
2951
  ).describe("All endorsements found in the document")
2858
2952
  });
2859
2953
  function buildEndorsementsPrompt() {
2860
2954
  return `You are an expert insurance document analyst. Extract ALL endorsements from this document. Preserve original language verbatim.
2861
2955
 
2862
- Focus on:
2863
- - Every endorsement listed in the forms schedule or endorsement schedule
2864
- - Standalone endorsements modifying the base policy
2865
- - Form number and edition date (e.g. "CG 21 47 12 07")
2866
- - Endorsement title and full verbatim content
2867
- - Effect type: "broadening" if it adds or expands coverage, "restrictive" if it limits or excludes coverage, "informational" if it changes administrative terms only
2868
- - Additional premium or credit shown on the endorsement
2869
- - Named parties: additional insureds, loss payees, certificate holders, mortgagees
2956
+ For EACH endorsement, extract:
2957
+ - formNumber: the form identifier (e.g. "CG 21 47") \u2014 REQUIRED
2958
+ - editionDate: the edition date if present (e.g. "12 07")
2959
+ - title: endorsement title \u2014 REQUIRED
2960
+ - endorsementType: classify as one of: additional_insured, waiver_of_subrogation, primary_noncontributory, blanket_additional_insured, loss_payee, mortgage_holder, broadening, restriction, exclusion, amendatory, notice_of_cancellation, designated_premises, classification_change, schedule_update, deductible_change, limit_change, territorial_extension, other
2961
+ - effectiveDate: endorsement effective date if shown
2962
+ - affectedCoverageParts: which coverage parts are modified
2963
+ - namedParties: for each party, extract name, role (additional_insured, loss_payee, mortgage_holder, certificate_holder, waiver_beneficiary, designated_person, other), relationship, and scope
2964
+ - keyTerms: notable provisions or key terms
2965
+ - premiumImpact: additional premium or credit if shown
2966
+ - content: full verbatim text \u2014 REQUIRED
2967
+ - pageStart: page number where endorsement begins \u2014 REQUIRED
2968
+ - pageEnd: page number where endorsement ends
2870
2969
 
2871
2970
  PERSONAL LINES ENDORSEMENT RECOGNITION:
2872
2971
  - HO 04 XX series: homeowners endorsements
@@ -2882,23 +2981,39 @@ import { z as z25 } from "zod";
2882
2981
  var ExclusionsSchema = z25.object({
2883
2982
  exclusions: z25.array(
2884
2983
  z25.object({
2885
- title: z25.string().describe("Exclusion title or short description"),
2886
- content: z25.string().optional().describe("Full verbatim exclusion text"),
2984
+ name: z25.string().describe("Exclusion title or short description"),
2887
2985
  formNumber: z25.string().optional().describe("Form number if part of a named endorsement"),
2888
- appliesTo: z25.string().optional().describe("Coverage type this exclusion applies to")
2986
+ excludedPerils: z25.array(z25.string()).optional().describe("Specific perils excluded"),
2987
+ isAbsolute: z25.boolean().optional().describe("Whether the exclusion is absolute (no exceptions)"),
2988
+ exceptions: z25.array(z25.string()).optional().describe("Exceptions to the exclusion, if any"),
2989
+ buybackAvailable: z25.boolean().optional().describe("Whether coverage can be bought back via endorsement"),
2990
+ buybackEndorsement: z25.string().optional().describe("Form number of the buyback endorsement if available"),
2991
+ appliesTo: z25.array(z25.string()).optional().describe("Coverage types this exclusion applies to"),
2992
+ content: z25.string().describe("Full verbatim exclusion text"),
2993
+ pageNumber: z25.number().optional().describe("Page number where exclusion appears")
2889
2994
  })
2890
2995
  ).describe("All exclusions found in the document")
2891
2996
  });
2892
2997
  function buildExclusionsPrompt() {
2893
2998
  return `You are an expert insurance document analyst. Extract ALL exclusions from this document. Preserve original language verbatim.
2894
2999
 
3000
+ For EACH exclusion, extract:
3001
+ - name: exclusion title or short description \u2014 REQUIRED
3002
+ - formNumber: form number if the exclusion is part of a named endorsement
3003
+ - excludedPerils: specific perils being excluded
3004
+ - isAbsolute: true if the exclusion has no exceptions, false if exceptions exist
3005
+ - exceptions: any exceptions to the exclusion (things still covered despite the exclusion)
3006
+ - buybackAvailable: whether coverage can be purchased back via endorsement
3007
+ - buybackEndorsement: the form number of the buyback endorsement if known
3008
+ - appliesTo: which coverage types or lines this exclusion applies to (as an array)
3009
+ - content: full verbatim exclusion text \u2014 REQUIRED
3010
+ - pageNumber: page number where the exclusion appears
3011
+
2895
3012
  Focus on:
2896
3013
  - Named exclusions from exclusion schedules
2897
3014
  - Exclusions embedded within endorsements
2898
3015
  - Exclusions within insuring agreements or conditions if clearly labeled
2899
3016
  - Full verbatim exclusion text \u2014 do not summarize
2900
- - Form number if the exclusion is part of a named endorsement
2901
- - Which coverage line the exclusion applies to, if specific
2902
3017
 
2903
3018
  Common personal lines exclusion patterns: animal liability, business pursuits, home daycare, watercraft, aircraft.
2904
3019
 
@@ -2910,43 +3025,62 @@ import { z as z26 } from "zod";
2910
3025
  var ConditionsSchema = z26.object({
2911
3026
  conditions: z26.array(
2912
3027
  z26.object({
2913
- type: z26.enum([
3028
+ name: z26.string().describe("Condition title"),
3029
+ conditionType: z26.enum([
2914
3030
  "duties_after_loss",
2915
- "cooperation",
3031
+ "notice_requirements",
3032
+ "other_insurance",
2916
3033
  "cancellation",
2917
3034
  "nonrenewal",
2918
- "subrogation",
2919
- "other_insurance",
2920
3035
  "transfer_of_rights",
2921
- "examination_under_oath",
2922
- "arbitration",
2923
- "suit_against_us",
2924
3036
  "liberalization",
3037
+ "arbitration",
3038
+ "concealment_fraud",
3039
+ "examination_under_oath",
3040
+ "legal_action",
3041
+ "loss_payment",
3042
+ "appraisal",
3043
+ "mortgage_holders",
3044
+ "policy_territory",
3045
+ "separation_of_insureds",
2925
3046
  "other"
2926
- ]).optional().describe("Condition category"),
2927
- title: z26.string().describe("Condition title"),
2928
- content: z26.string().optional().describe("Full verbatim condition text"),
2929
- noticeDays: z26.number().optional().describe("Notice period in days if specified (e.g. cancellation notice)")
3047
+ ]).describe("Condition category"),
3048
+ content: z26.string().describe("Full verbatim condition text"),
3049
+ keyValues: z26.array(
3050
+ z26.object({
3051
+ key: z26.string().describe("Key name (e.g. 'noticePeriod', 'suitDeadline')"),
3052
+ value: z26.string().describe("Value (e.g. '30 days', '2 years')")
3053
+ })
3054
+ ).optional().describe("Key values extracted from the condition (notice periods, deadlines, etc.)"),
3055
+ pageNumber: z26.number().optional().describe("Page number where condition appears")
2930
3056
  })
2931
3057
  ).describe("All policy conditions found in the document")
2932
3058
  });
2933
3059
  function buildConditionsPrompt() {
2934
3060
  return `You are an expert insurance document analyst. Extract ALL policy conditions from this document. Preserve original language verbatim.
2935
3061
 
3062
+ For EACH condition, extract:
3063
+ - name: condition title \u2014 REQUIRED
3064
+ - conditionType: classify as one of: duties_after_loss, notice_requirements, other_insurance, cancellation, nonrenewal, transfer_of_rights, liberalization, arbitration, concealment_fraud, examination_under_oath, legal_action, loss_payment, appraisal, mortgage_holders, policy_territory, separation_of_insureds, other \u2014 REQUIRED
3065
+ - content: full verbatim condition text \u2014 REQUIRED
3066
+ - keyValues: extract specific values as key-value pairs (e.g. noticePeriod: "30 days", suitDeadline: "2 years")
3067
+ - pageNumber: page number where the condition appears
3068
+
2936
3069
  Focus on:
2937
3070
  - Duties after loss / notice of occurrence conditions
2938
- - Cooperation clause
2939
- - Cancellation and nonrenewal conditions (extract notice period in days)
2940
- - Subrogation / transfer of rights
3071
+ - Notice requirements (extract notice period as keyValue)
3072
+ - Cancellation and nonrenewal conditions (extract notice period in days as keyValue)
2941
3073
  - Other insurance clause
3074
+ - Subrogation / transfer of rights
2942
3075
  - Examination under oath
2943
3076
  - Arbitration or appraisal provisions
2944
3077
  - Suit against us / legal action conditions
2945
3078
  - Liberalization clause
3079
+ - Concealment or fraud clause
3080
+ - Loss payment conditions
3081
+ - Mortgage holders clause
2946
3082
  - Any other named conditions
2947
3083
 
2948
- For cancellation and nonrenewal conditions, extract the specific notice period in days if stated.
2949
-
2950
3084
  Return JSON only.`;
2951
3085
  }
2952
3086
 
@@ -3227,12 +3361,16 @@ function createExtractor(config) {
3227
3361
  },
3228
3362
  {
3229
3363
  fallback: { documentType: "policy", policyTypes: ["other"], confidence: 0 },
3364
+ maxRetries: 3,
3230
3365
  log,
3231
- onError: (err, attempt) => log?.(`Classify attempt ${attempt + 1} failed: ${err}`)
3366
+ onError: (err, attempt) => log?.(`Classify attempt ${attempt + 1} failed: ${err instanceof Error ? err.message : String(err)}`)
3232
3367
  }
3233
3368
  );
3234
3369
  trackUsage(classifyResponse.usage);
3235
3370
  classifyResult = classifyResponse.object;
3371
+ if (classifyResult.confidence === 0) {
3372
+ await log?.(`WARNING: classify returned fallback (policyTypes: ["other"]). This usually means the generateObject callback failed \u2014 check that the document content is accessible to the model.`);
3373
+ }
3236
3374
  memory.set("classify", classifyResult);
3237
3375
  await pipelineCtx.save("classify", {
3238
3376
  id,