Skip to content

Commit c646de0

Browse files
authored
fix: validate LLM work experience squash result (#4059)
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
1 parent 3232b22 commit c646de0

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

  • services/apps/members_enrichment_worker/src/activities

services/apps/members_enrichment_worker/src/activities/llm.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ export async function squashWorkExperiencesWithLLM(
327327
"startDate": "2020-06-01",
328328
"endDate": "2021-12-31",
329329
"source": "LinkedIn"
330-
}
330+
},
331331
{
332332
"name": "Company Y",
333333
"title": "Manager",
@@ -338,8 +338,7 @@ export async function squashWorkExperiencesWithLLM(
338338
]
339339
340340
Ensure the response is a **valid and complete JSON**.
341-
DO NOT output anything else.
342-
Output ONLY valid JSON
341+
Output ONLY valid JSON array. DO NOT output anything else.
343342
`
344343

345344
const llmService = new LlmService(
@@ -351,8 +350,15 @@ export async function squashWorkExperiencesWithLLM(
351350
svc.log,
352351
)
353352

354-
const result = await llmService.squashWorkExperiencesFromMultipleSources<
353+
const res = await llmService.squashWorkExperiencesFromMultipleSources<
355354
IMemberEnrichmentDataNormalizedOrganization[]
356355
>(memberId, prompt)
357-
return result.result
356+
357+
if (!Array.isArray(res?.result)) {
358+
const errorMessage = 'LLM returned invalid work experiences payload shape!'
359+
svc.log.warn({ memberId, result: res?.result }, errorMessage)
360+
throw new Error(errorMessage)
361+
}
362+
363+
return res.result
358364
}

0 commit comments

Comments
 (0)