diff options
Diffstat (limited to 'packages')
| -rw-r--r-- | packages/gateway/src/listeners/moderationAgent/utilities.ts | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/packages/gateway/src/listeners/moderationAgent/utilities.ts b/packages/gateway/src/listeners/moderationAgent/utilities.ts index eb520c7..2e6542e 100644 --- a/packages/gateway/src/listeners/moderationAgent/utilities.ts +++ b/packages/gateway/src/listeners/moderationAgent/utilities.ts @@ -272,16 +272,18 @@ CONFIDENCE GUIDELINES: - 0-39%: Low confidence, likely false positive RESPONSE FORMAT: -You must respond with valid JSON in this exact format: +You must respond with ONLY valid JSON in this exact format. Do not include any text before or after the JSON: { "violation": boolean, "rule": "Rule number and brief description if violation found, empty string if none", "severity": "low|medium|high|critical", "explanation": "Detailed explanation of the violation or why it's acceptable", "brief": "Short one-sentence explanation for why it was flagged (if violation) or why it's acceptable (if no violation)", - "confidence": number (0-100, how confident you are in this assessment) + "confidence": number } +CRITICAL: Your response must be ONLY the JSON object above. No explanations, no markdown, no additional text. Start with { and end with }. All string values must use double quotes, not single quotes. Escape any quotes in string values with backslashes. + If no violation is found, set "violation" to false and provide a brief explanation of why the message is acceptable. Remember: Only enforce the exact rules provided. Do not make assumptions or interpretations beyond what is explicitly stated in the SERVER_RULES section. Adult sexual content between adults is NOT a violation unless it explicitly breaks a stated rule.`; @@ -350,6 +352,19 @@ Remember: Only enforce the exact rules provided. Do not make assumptions or inte } } + if (!jsonContent.startsWith("{")) { + const jsonMatch = jsonContent.match(/\{[\s\S]*\}/); + + if (jsonMatch) jsonContent = jsonMatch[0]; + } + + jsonContent = jsonContent + .replace(/\\'/g, "'") + .replace(/'/g, '"') + .replace(/(\w+):/g, '"$1":') + .replace(/,\s*}/g, "}") + .replace(/,\s*]/g, "]"); + return JSON.parse(jsonContent); } catch (parseError) { console.error("Failed to parse OpenRouter response as JSON:", content); |