diff --git a/index.html b/index.html index 5fbb70f..4a99755 100644 --- a/index.html +++ b/index.html @@ -10127,17 +10127,27 @@ Analyze and refine. Output ONLY the JSON object:` } break; } - // Parse the JSON response + // Parse and strictly normalize the JSON response let result; try { - // Extract JSON from potential markdown code blocks const jsonMatch = refinerOutput.match(/\{[\s\S]*\}/); if (!jsonMatch) throw new Error('No JSON found in refiner output'); - result = JSON.parse(jsonMatch[0]); + const raw = JSON.parse(jsonMatch[0]); + // Normalize: clamp numbers, bound strings, filter arrays + result = { + currentScore: Math.max(0, Math.min(100, Number(raw.currentScore) || 0)), + refinedScore: Math.max(0, Math.min(100, Number(raw.refinedScore) || 0)), + qualityDelta: Math.max(-100, Math.min(100, Number(raw.qualityDelta) || 0)), + converged: !!raw.converged, + refinedContent: typeof raw.refinedContent === 'string' ? raw.refinedContent : '', + improvements: (Array.isArray(raw.improvements) ? raw.improvements : []) + .filter(x => typeof x === 'string') + .slice(0, 10) + .map(s => s.slice(0, 200)), + }; } catch (parseErr) { console.error('[LIQUID] Failed to parse refiner output:', parseErr.message); console.error('[LIQUID] Raw output:', refinerOutput.slice(0, 500)); - // Don't break on first parse failure — try next iteration continue; } @@ -10751,28 +10761,36 @@ Analyze and refine. Output ONLY the JSON object:` }