fix(guard): 근거 텍스트와 표기만 다른 수치(띄어쓰기·단위 표기)도 근거 있는 값으로 인정(두 자리 이상 수치가 근거에 독립된 숫자로 있을 때)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
kimandClaude Sonnet 5.5 committed 2026-10-05 12:50:36 +09:00
1 parent 75710ddcf9
commit 76c6790110
2 files changed
+17 -1

No files matched your search

+9 -1
View File
@@ -292,7 +292,15 @@ function blankGroundedClaims(text: string, groundText: string): string {
const g = String(groundText || '').replace(/\s+/g, '').toLowerCase();
if (!g) return text;
const re = new RegExp([STRICT_SPEC_UNITS, MEASUREMENT_UNITS, AMBIGUOUS_SPEC_UNITS].map(r => r.source).join('|'), 'gi');
return text.replace(re, m => (g.includes(m.replace(/\s+/g, '').toLowerCase()) ? '' : m));
return text.replace(re, m => {
const norm = m.replace(/\s+/g, '').toLowerCase();
if (g.includes(norm)) return ''; // 같은 수치+단위가 그대로 있음
// 표기만 다른 경우(%·mm 띄어쓰기, 'cm'↔'㎝' 등): 두 글자 이상 수치(20.3, 236)가 근거에 독립된 숫자로 있으면 근거 있는 값으로 본다.
// 한 자리 수는 우연히 맞기 쉬워서 단위까지 일치해야만 인정한다(위 분기).
const num = (norm.match(/^\d[\d,.]*/) || [''])[0].replace(/[.,]+$/, '');
if (num.length >= 2 && new RegExp(`(?<![\\d.])${num.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}(?![\\d.])`).test(String(groundText))) return '';
return m;
});
}
/**
+8
View File
@@ -50,6 +50,14 @@ describe('AUTO-RECOVER — 근거 없이 답한 경우 재시도', () => {
assert.equal(decideAutoRecover({ message: 'RTX 5090이랑 4090 성능 비교해 줘', content: '5090이 더 빠릅니다.', availableToolNames: ['web_search'], calledToolNames: [], providedContext: ctx }).shouldRetry, true);
});
test('[2026-10-05] 표기만 다른 근거 수치(띄어쓰기·단위 표기)는 지어낸 값이 아니다', () => {
const ctx = 'Results: 236 cavities, incidence 20.3 percent, cavity depth 3 mm, 15.7-25.9 %';
const ans = '발생률은 20.3% 였고 와동 깊이는 3mm, 신뢰구간 15.7%~25.9% 였다.';
assert.equal(decideAutoRecover({ message: '지정한 논문 요약', content: ans, availableToolNames: ['web_search'], calledToolNames: [], providedContext: ctx }).shouldRetry, false);
// 근거에 없는 두 자리 이상 수치는 여전히 걸린다
assert.equal(decideAutoRecover({ message: '지정한 논문 요약', content: '와동 깊이는 7.4mm 였다.', availableToolNames: ['web_search'], calledToolNames: [], providedContext: ctx }).shouldRetry, true);
});
test('이미 검색했으면 재시도하지 않는다', () => {
assert.equal(recover('RTX 5090 스펙', 'VRAM 32GB입니다.', ['web_search']).shouldRetry, false);
});