Skip to content

Commit 853ae9a

Browse files
author
Peter Kumberger
committed
Changed prompt such that redaction suggestion tool call is actually run
1 parent 72969b2 commit 853ae9a

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/app/api/chat/route.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import type { ChatRequest, ApiChatMessage } from '@/types'
1111
type SSEController = ReadableStreamDefaultController
1212
const enc = new TextEncoder()
1313

14+
// Heuristic only, for diagnostics: catches a model narrating "I've suggested N
15+
// redactions" (or the equivalent in another supported locale) in plain text
16+
// instead of actually calling suggest_redactions. Not perfect, but a false
17+
// positive here only produces an extra log line, never a behavior change.
18+
const SUGGESTS_REDACTIONS_WITHOUT_CALLING = /\d+[^.!?\n]{0,40}(suggest|redact|vorschl|schwärz|schw[aä]rzung|proposi|masqu|suprim|suger|ocult|редак|предлож||||تنقيح|اقتراح)/i
19+
1420
function send(ctrl: SSEController, event: Record<string, unknown>) {
1521
ctrl.enqueue(enc.encode(`data: ${JSON.stringify(event)}\n\n`))
1622
}
@@ -121,6 +127,15 @@ export async function POST(req: Request) {
121127
type: 'error',
122128
message: `The model stopped without a reply after ${MAX_EMPTY_RETRIES + 1} attempts (finish_reason: ${finishReason ?? 'unknown'}). This is usually the model getting stuck retrying a tool call rather than a context-length issue — try asking again or rephrasing.`,
123129
})
130+
} else if (SUGGESTS_REDACTIONS_WITHOUT_CALLING.test(assistantContent)) {
131+
// The model described making suggestions in prose without an actual
132+
// suggest_redactions call — nothing was applied. Already streamed to the
133+
// client as text, so this can only be logged for now, not corrected
134+
// in-place; see it as a signal that the tool schema or prompt needs
135+
// another look if it keeps recurring.
136+
console.warn('[chat] claimed suggest_redactions without calling it', {
137+
finishReason, content: assistantContent,
138+
})
124139
}
125140
send(ctrl, { type: 'done' })
126141
break

src/lib/system-prompt.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ export function buildSystemPrompt(opts: {
5252
'4. **Targeted follow-up questions**: Only ask questions that arise from the actual document content — about persons or cases that are genuinely unclear. Ask concretely, not abstractly.',
5353
'5. **Make suggestions**: As soon as you have identified what to redact, call `suggest_redactions` directly — do NOT describe the candidates in chat text first and ask "should I add these?". The suggestions already land in the sidebar/document as a reviewable, reversible proposal, so that preview step is redundant and slows the user down. Only ask first if a genuine ambiguity needs resolving (step 4).',
5454
'',
55+
'NEVER claim, state, or imply that redactions were suggested, added, or found unless you are ACTUALLY invoking `suggest_redactions` as a real tool call in this exact same response. A sentence like "I have suggested 12 redactions" is only true right after the corresponding tool call — writing that sentence without making the call is a false statement to the user and creates suggestions that do not actually exist anywhere. If you are unsure how to structure the call, still attempt the real tool call — do not fall back to describing it in plain text instead.',
56+
'',
5557
'## Redaction modes',
5658
'',
5759
'Two redaction modes exist. The user selects the mode in the menu, before this conversation starts — do NOT ask about it, via `ask_user` or otherwise, under any circumstances.',

0 commit comments

Comments
 (0)