From 40a0513b05f5b3419f74f60879826ba97ac0e533 Mon Sep 17 00:00:00 2001 From: hailin Date: Sat, 7 Feb 2026 08:59:19 -0800 Subject: [PATCH] fix(agents): strip markdown code fences from InputGate Haiku response Haiku sometimes returns JSON wrapped in ```json ... ``` code blocks, causing JSON.parse to fail. Strip markdown fences before parsing. Co-Authored-By: Claude Opus 4.6 --- .../infrastructure/agents/coordinator/input-gate.service.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/services/conversation-service/src/infrastructure/agents/coordinator/input-gate.service.ts b/packages/services/conversation-service/src/infrastructure/agents/coordinator/input-gate.service.ts index bf3c52b..97aa7be 100644 --- a/packages/services/conversation-service/src/infrastructure/agents/coordinator/input-gate.service.ts +++ b/packages/services/conversation-service/src/infrastructure/agents/coordinator/input-gate.service.ts @@ -61,7 +61,9 @@ export class InputGateService { temperature: 0, }); - const text = (response.content[0] as { type: string; text?: string })?.text || ''; + const rawText = (response.content[0] as { type: string; text?: string })?.text || ''; + // Haiku sometimes wraps JSON in ```json ... ``` — strip markdown code fences + const text = rawText.replace(/^```(?:json)?\s*\n?/i, '').replace(/\n?```\s*$/i, '').trim(); const parsed = JSON.parse(text); const classification: InputClassification = parsed.classification || 'ON_TOPIC';