Skip to content

Commit 0055c0d

Browse files
committed
fix: add error handling for invalid JSON responses in member bot analysis
1 parent f7e7257 commit 0055c0d

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

services/apps/profiles_worker/src/workflows/member/processMemberBotAnalysisWithLLM.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { proxyActivities } from '@temporalio/workflow'
1+
import { ApplicationFailure, proxyActivities } from '@temporalio/workflow'
22

33
import { LlmQueryType } from '@crowd/types'
44

@@ -75,6 +75,12 @@ export async function processMemberBotAnalysisWithLLM(
7575
const start = llm.answer.indexOf('{')
7676
const end = llm.answer.lastIndexOf('}')
7777

78+
if (start === -1 || end === -1) {
79+
throw ApplicationFailure.retryable(
80+
`LLM returned no valid JSON object for member ${memberId}: ${llm.answer.substring(0, 200)}`,
81+
)
82+
}
83+
7884
const { isBot, signals } = JSON.parse(
7985
llm.answer.substring(start, end + 1),
8086
) as MemberBotSuggestionResult

0 commit comments

Comments
 (0)