Skip to content

fix: validate ReceiptBuilder ngram and threshold - #22

Merged
royalpinto007 merged 3 commits into
AgentPostmortem:mainfrom
HarshRajSinghania:fix/validate-builder-ngram-threshold
Sep 11, 2026
Merged

fix: validate ReceiptBuilder ngram and threshold#22
royalpinto007 merged 3 commits into
AgentPostmortem:mainfrom
HarshRajSinghania:fix/validate-builder-ngram-threshold

Conversation

@HarshRajSinghania

Copy link
Copy Markdown
Contributor

Summary

Validate ReceiptBuilder construction parameters so degenerate citation settings cannot silently produce a perfect grounding score.

Motivation

Fixes #20. ngram=0 produces an empty gram set that matches every claim (grounding_score 1.0). threshold was also accepted outside [0, 1].

Implementation

  • ReceiptBuilder.__init__ now raises ValueError when ngram < 1 (including 0 and negatives) or when threshold is outside [0, 1].
  • Boolean values are rejected for both parameters because bool is a subclass of int.
  • Default ngram=3 / threshold=0.5 behavior is unchanged.

Testing

Ran locally:

PYTHONPATH=src pytest tests/ -q

Result: 96 passed.

Added tests in tests/test_builder.py for ngram=0, negative ngram, threshold=1.5, threshold=-0.1, and boundary values 0.0/1.0.

@royalpinto007
royalpinto007 merged commit da94e5d into AgentPostmortem:main Sep 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ReceiptBuilder accepts ngram=0 / out-of-range threshold, corrupting grounding

2 participants