@claritylabs/cl-sdk 0.7.4 → 0.8.0

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
@@ -1525,19 +1525,28 @@ async function runExtractor(params) {
1525
1525
  maxTokens = 4096,
1526
1526
  providerOptions
1527
1527
  } = params;
1528
- const pagesPdf = await extractPageRange(pdfBase64, startPage, endPage);
1529
- const fullPrompt = convertPdfToImages ? `${prompt}
1530
-
1531
- [Document pages ${startPage}-${endPage} are provided as images above.]` : `${prompt}
1528
+ const extractorProviderOptions = { ...providerOptions };
1529
+ let fullPrompt;
1530
+ if (convertPdfToImages) {
1531
+ const images = await convertPdfToImages(pdfBase64, startPage, endPage);
1532
+ extractorProviderOptions.images = images;
1533
+ fullPrompt = `${prompt}
1534
+
1535
+ [Document pages ${startPage}-${endPage} are provided as images.]`;
1536
+ } else {
1537
+ const pagesPdf = await extractPageRange(pdfBase64, startPage, endPage);
1538
+ extractorProviderOptions.pdfBase64 = pagesPdf;
1539
+ fullPrompt = `${prompt}
1532
1540
 
1533
- [Document pages ${startPage}-${endPage} are provided as a PDF file above.]`;
1541
+ [Document pages ${startPage}-${endPage} are provided as a PDF file.]`;
1542
+ }
1534
1543
  const strictSchema = toStrictSchema(schema);
1535
1544
  const result = await withRetry(
1536
1545
  () => generateObject({
1537
1546
  prompt: fullPrompt,
1538
1547
  schema: strictSchema,
1539
1548
  maxTokens,
1540
- providerOptions
1549
+ providerOptions: extractorProviderOptions
1541
1550
  })
1542
1551
  );
1543
1552
  return {
@@ -2616,29 +2625,73 @@ function getTemplate(policyType) {
2616
2625
  // src/prompts/coordinator/classify.ts
2617
2626
  import { z as z18 } from "zod";
2618
2627
  var ClassifyResultSchema = z18.object({
2619
- documentType: z18.enum(["policy", "quote"]),
2620
- policyTypes: z18.array(PolicyTypeSchema),
2621
- confidence: z18.number()
2628
+ documentType: z18.enum(["policy", "quote"]).describe("Whether this is a bound policy or a proposed quote"),
2629
+ policyTypes: z18.array(PolicyTypeSchema).min(1).describe("Lines of business covered \u2014 at least one required"),
2630
+ confidence: z18.number().describe("Confidence score from 0.0 to 1.0")
2622
2631
  });
2623
2632
  function buildClassifyPrompt() {
2624
- return `You are classifying an insurance document. Examine the first few pages and determine:
2633
+ return `You are classifying an insurance document. Examine the document and determine:
2625
2634
 
2626
2635
  1. Whether this is a POLICY (bound coverage) or QUOTE (proposed coverage)
2627
- 2. What lines of business are covered
2628
-
2629
- Policies typically have: policy numbers, effective/expiration dates, declarations pages, premium charges.
2630
- Quotes typically have: quote numbers, proposed dates, subjectivities, "indication" or "proposal" language.
2631
-
2632
- Return JSON matching this structure:
2636
+ 2. What lines of business are covered (at least one \u2014 never return an empty list)
2637
+
2638
+ POLICY indicators: policy numbers, effective/expiration dates, declarations pages, premium charges, "this policy" language.
2639
+ QUOTE indicators: quote numbers, proposed dates, subjectivities, "indication" or "proposal" language, "quoted premium".
2640
+
2641
+ COMMERCIAL LINES \u2014 match these values:
2642
+ - "general_liability" \u2014 CGL, commercial general liability, GL
2643
+ - "commercial_property" \u2014 commercial property, building/contents coverage
2644
+ - "commercial_auto" \u2014 commercial auto, business auto, CA
2645
+ - "non_owned_auto" \u2014 hired & non-owned auto
2646
+ - "workers_comp" \u2014 workers compensation, WC
2647
+ - "umbrella" \u2014 commercial umbrella
2648
+ - "excess_liability" \u2014 excess liability, follow-form excess
2649
+ - "professional_liability" \u2014 E&O, errors & omissions, professional liability, malpractice
2650
+ - "cyber" \u2014 cyber liability, data breach, network security
2651
+ - "epli" \u2014 employment practices liability
2652
+ - "directors_officers" \u2014 D&O, directors and officers
2653
+ - "fiduciary_liability" \u2014 fiduciary liability
2654
+ - "crime_fidelity" \u2014 crime, fidelity, employee dishonesty
2655
+ - "inland_marine" \u2014 inland marine, equipment floater, contractors equipment
2656
+ - "builders_risk" \u2014 builders risk, course of construction
2657
+ - "environmental" \u2014 environmental, pollution liability
2658
+ - "ocean_marine" \u2014 ocean marine, cargo, hull
2659
+ - "surety" \u2014 surety bond
2660
+ - "product_liability" \u2014 product liability, products-completed operations
2661
+ - "bop" \u2014 business owners policy, BOP
2662
+ - "management_liability_package" \u2014 management liability package
2663
+ - "property" \u2014 standalone property
2664
+
2665
+ PERSONAL LINES \u2014 match these values:
2666
+ - "homeowners_ho3" \u2014 HO-3, special form homeowners
2667
+ - "homeowners_ho5" \u2014 HO-5, comprehensive form homeowners
2668
+ - "renters_ho4" \u2014 HO-4, renters insurance
2669
+ - "condo_ho6" \u2014 HO-6, condo unit-owners
2670
+ - "dwelling_fire" \u2014 DP-1, DP-3, dwelling fire
2671
+ - "mobile_home" \u2014 mobile home, manufactured home
2672
+ - "personal_auto" \u2014 personal auto, PAP
2673
+ - "personal_umbrella" \u2014 personal umbrella
2674
+ - "flood_nfip" \u2014 NFIP flood
2675
+ - "flood_private" \u2014 private flood
2676
+ - "earthquake" \u2014 earthquake
2677
+ - "personal_inland_marine" \u2014 personal articles, scheduled personal property
2678
+ - "watercraft" \u2014 watercraft, boat
2679
+ - "recreational_vehicle" \u2014 RV, recreational vehicle, ATV
2680
+ - "farm_ranch" \u2014 farm, ranch
2681
+ - "pet" \u2014 pet insurance
2682
+ - "travel" \u2014 travel insurance
2683
+ - "identity_theft" \u2014 identity theft
2684
+ - "title" \u2014 title insurance
2685
+ - "other" \u2014 only if NONE of the above match
2686
+
2687
+ 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.
2688
+
2689
+ Return JSON only:
2633
2690
  {
2634
2691
  "documentType": "policy" | "quote",
2635
- "policyTypes": ["general_liability", "commercial_property", ...],
2692
+ "policyTypes": ["general_liability", ...],
2636
2693
  "confidence": 0.0-1.0
2637
- }
2638
-
2639
- 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.
2640
-
2641
- Respond with JSON only.`;
2694
+ }`;
2642
2695
  }
2643
2696
 
2644
2697
  // src/prompts/coordinator/plan.ts
@@ -3313,16 +3366,20 @@ function createExtractor(config) {
3313
3366
  prompt: buildClassifyPrompt(),
3314
3367
  schema: ClassifyResultSchema,
3315
3368
  maxTokens: 512,
3316
- providerOptions
3369
+ providerOptions: { ...providerOptions, pdfBase64 }
3317
3370
  },
3318
3371
  {
3319
3372
  fallback: { documentType: "policy", policyTypes: ["other"], confidence: 0 },
3373
+ maxRetries: 3,
3320
3374
  log,
3321
- onError: (err, attempt) => log?.(`Classify attempt ${attempt + 1} failed: ${err}`)
3375
+ onError: (err, attempt) => log?.(`Classify attempt ${attempt + 1} failed: ${err instanceof Error ? err.message : String(err)}`)
3322
3376
  }
3323
3377
  );
3324
3378
  trackUsage(classifyResponse.usage);
3325
3379
  classifyResult = classifyResponse.object;
3380
+ if (classifyResult.confidence === 0) {
3381
+ 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.`);
3382
+ }
3326
3383
  memory.set("classify", classifyResult);
3327
3384
  await pipelineCtx.save("classify", {
3328
3385
  id,
@@ -3353,7 +3410,7 @@ function createExtractor(config) {
3353
3410
  prompt: buildPlanPrompt(templateHints),
3354
3411
  schema: ExtractionPlanSchema,
3355
3412
  maxTokens: 2048,
3356
- providerOptions
3413
+ providerOptions: { ...providerOptions, pdfBase64 }
3357
3414
  },
3358
3415
  {
3359
3416
  fallback: {