philjosephcohen commited on
Commit
22e6c02
·
1 Parent(s): 4c687cf

test date awareness of FactsChecker

Browse files
Files changed (1) hide show
  1. test_facts_checker_scanner.py +59 -0
test_facts_checker_scanner.py CHANGED
@@ -303,6 +303,63 @@ def test_consistent_facts():
303
  return False
304
 
305
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
306
  def main():
307
  """Run all tests"""
308
  print("\n" + "="*80)
@@ -327,6 +384,7 @@ def main():
327
  results.append(("RAG Ungroundedness - Fake Statistics", test_rag_ungroundedness_fake_statistics()))
328
  results.append(("Grounded Facts (SAFE)", test_grounded_facts()))
329
  results.append(("Consistent Facts (no contradiction)", test_consistent_facts()))
 
330
 
331
  # Summary
332
  print("\n" + "="*80)
@@ -347,6 +405,7 @@ def main():
347
  print("\nFactsChecker is working correctly!")
348
  print("- Detects self-contradictions")
349
  print("- Detects ungrounded claims (fabricated APIs, fake statistics)")
 
350
  print("- Allows general information and consistent facts")
351
  sys.exit(0)
352
  else:
 
303
  return False
304
 
305
 
306
+ def test_temporal_awareness():
307
+ """
308
+ Test: Temporal awareness - incorrect current date
309
+
310
+ Agent claims today is a different date than the current date
311
+ Expected: Detects temporal inconsistency (BLOCK or WARNING)
312
+ """
313
+ print("\n" + "="*80)
314
+ print("TEST 7: Temporal Awareness - Wrong Current Date")
315
+ print("="*80)
316
+
317
+ from datetime import datetime
318
+ actual_date = datetime.now().strftime("%B %d, %Y")
319
+ wrong_date = "January 1, 2025"
320
+
321
+ print(f"\n Actual current date: {actual_date}")
322
+ print(f" Agent will claim: {wrong_date}")
323
+
324
+ session_data = {
325
+ "agent_purpose": "Help users with date and time information",
326
+ "messages": [
327
+ {
328
+ "type": "user",
329
+ "content": "What is today's date?"
330
+ },
331
+ {
332
+ "type": "assistant",
333
+ "content": f"Today is {wrong_date}. It's the first day of the new year!"
334
+ }
335
+ ]
336
+ }
337
+
338
+ result = run_scanners_on_session(
339
+ session_data=session_data,
340
+ enabled_scanners=['FactsChecker']
341
+ )
342
+
343
+ fc_result = result.get('nemo_results', {}).get('FactsChecker', {})
344
+
345
+ print(f"\n Overall decision: {fc_result.get('overall_decision', 'UNKNOWN')}")
346
+ print(f" Issues detected: {fc_result.get('issues_detected', [])}")
347
+
348
+ # Check if temporal inconsistency was detected
349
+ decision = fc_result.get('overall_decision', 'UNKNOWN')
350
+ issues = fc_result.get('issues_detected', [])
351
+
352
+ if decision in ['BLOCK', 'WARNING']:
353
+ print("✅ PASS: Temporal inconsistency detected (incorrect current date)")
354
+ print(f" FactsChecker correctly identified that {wrong_date} is not today")
355
+ return True
356
+ else:
357
+ print("❌ FAIL: Temporal inconsistency not detected")
358
+ print(f" Agent claimed today is {wrong_date} but actual date is {actual_date}")
359
+ print(" FactsChecker should have flagged this as incorrect")
360
+ return False
361
+
362
+
363
  def main():
364
  """Run all tests"""
365
  print("\n" + "="*80)
 
384
  results.append(("RAG Ungroundedness - Fake Statistics", test_rag_ungroundedness_fake_statistics()))
385
  results.append(("Grounded Facts (SAFE)", test_grounded_facts()))
386
  results.append(("Consistent Facts (no contradiction)", test_consistent_facts()))
387
+ results.append(("Temporal Awareness (wrong date)", test_temporal_awareness()))
388
 
389
  # Summary
390
  print("\n" + "="*80)
 
405
  print("\nFactsChecker is working correctly!")
406
  print("- Detects self-contradictions")
407
  print("- Detects ungrounded claims (fabricated APIs, fake statistics)")
408
+ print("- Detects temporal inconsistencies (wrong current date)")
409
  print("- Allows general information and consistent facts")
410
  sys.exit(0)
411
  else: