From 64f50bc35be51e0f6a02c09f822186e6a24566fb Mon Sep 17 00:00:00 2001 From: Yeganathan S <63534555+skwowet@users.noreply.github.com> Date: Mon, 27 Apr 2026 16:20:05 +0530 Subject: [PATCH] fix: validate LLM response shape for work experiences in squashWorkExperiencesWithLLM func Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com> --- .../src/activities/llm.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/services/apps/members_enrichment_worker/src/activities/llm.ts b/services/apps/members_enrichment_worker/src/activities/llm.ts index 8c47af2e08..2b97a54f0a 100644 --- a/services/apps/members_enrichment_worker/src/activities/llm.ts +++ b/services/apps/members_enrichment_worker/src/activities/llm.ts @@ -327,7 +327,7 @@ export async function squashWorkExperiencesWithLLM( "startDate": "2020-06-01", "endDate": "2021-12-31", "source": "LinkedIn" - } + }, { "name": "Company Y", "title": "Manager", @@ -338,8 +338,7 @@ export async function squashWorkExperiencesWithLLM( ] Ensure the response is a **valid and complete JSON**. - DO NOT output anything else. - Output ONLY valid JSON + Output ONLY valid JSON array. DO NOT output anything else. ` const llmService = new LlmService( @@ -351,8 +350,15 @@ export async function squashWorkExperiencesWithLLM( svc.log, ) - const result = await llmService.squashWorkExperiencesFromMultipleSources< + const res = await llmService.squashWorkExperiencesFromMultipleSources< IMemberEnrichmentDataNormalizedOrganization[] >(memberId, prompt) - return result.result + + if (!Array.isArray(res?.result)) { + const errorMessage = 'LLM returned invalid work experiences payload shape!' + svc.log.warn({ memberId, result: res?.result }, errorMessage) + throw new Error(errorMessage) + } + + return res.result }