Skip to content

Commit f7e7257

Browse files
committed
refactor: improve JSON response handling in member bot analysis
1 parent 89de347 commit f7e7257

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,9 @@ export async function processMemberBotAnalysisWithLLM(
5757
OUTPUT FORMAT:
5858
- Include "signals" object only when isBot: true
5959
- Omit fields from signals that provide no automation evidence
60-
IMPORTANT:
61-
- Your response must be raw JSON only.
62-
- No markdown, no code fences, no backticks, no explanation.
63-
- Start with { and end with }.
60+
- You must return ONLY valid JSON.
61+
- Do NOT add code fences, explanations, or extra text.
62+
- The JSON must begin with '{' and end with '}'.
6463
JSON SCHEMA:
6564
{
6665
"isBot": boolean,
@@ -73,8 +72,12 @@ export async function processMemberBotAnalysisWithLLM(
7372

7473
const llm = await getLLMResult(LlmQueryType.MEMBER_BOT_VALIDATION, PROMPT, memberId)
7574

76-
const answer = llm.answer.replace(/^```(?:json)?\s*|\s*```$/g, '').trim()
77-
const { isBot, signals } = JSON.parse(answer) as MemberBotSuggestionResult
75+
const start = llm.answer.indexOf('{')
76+
const end = llm.answer.lastIndexOf('}')
77+
78+
const { isBot, signals } = JSON.parse(
79+
llm.answer.substring(start, end + 1),
80+
) as MemberBotSuggestionResult
7881

7982
if (!isBot) {
8083
await createMemberNoBot(memberId)

0 commit comments

Comments
 (0)