Skip to content

API Reference parrot.security.groundedness.normalize

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.security.groundedness.normalize

View source

Normalization helpers for groundedness atom extraction (FEAT-398).

All functions are pure, synchronous, and stdlib-only (re, datetime, unicodedata). They fold surface-form variation (magnitude suffixes, thousand/decimal separators, multi-format dates, identifier casing, fullwidth Unicode forms) into canonical comparison keys so the same real-world fact compares equal regardless of how it was written in the answer vs. the evidence.

Function count_significant_digits

Count the significant digits in a numeric literal.

Backs the precision-aware tolerance rule (spec §2): a number with a magnitude suffix (1.24M) is a rounded statement with few significant digits, while a fully written number (1,234,500) is an exact statement whose digit count equals its length (trailing zeros in a fully written integer count as significant, per the spec's own worked example). Thousand separators, a leading sign, currency symbols, and the percent sign do not count; the magnitude suffix character itself does not count. Leading zeros before the first non-zero digit are never significant (standard sig-fig convention) — e.g. "0.005" has 1 significant digit, not 4.

count_significant_digits(raw: str) -> int

Parameter Type Default Description
raw str The raw numeric literal, e.g. "$1.24M" or "1,234,500".

Returns: int — The number of significant digit characters.

Function nfkc_normalize

Apply an NFKC Unicode normalization pre-pass to text.

Folds fullwidth/compatibility forms (e.g. fullwidth digits, fullwidth currency signs) into their canonical ASCII-compatible equivalents so downstream regex extractors see a consistent character set.

nfkc_normalize(text: str) -> str

Parameter Type Default Description
text str Raw input text.

Returns: str — The NFKC-normalized text.

Function normalize_date

Normalize a date literal in common en-US formats to ISO-8601.

Supported input formats: MM/DD/YYYY, Month DD, YYYY (full or abbreviated month names), and YYYY-MM-DD (validated pass-through).

normalize_date(raw: str) -> str

Parameter Type Default Description
raw str The raw date literal as it appeared in text.

Returns: str — The ISO-8601 date string (YYYY-MM-DD).

Raises:

  • ValueError — If raw does not match any supported date format, or names an unrecognized month.

Function normalize_identifier

Normalize an identifier (email, URL, ticket/SKU code) for comparison.

Applies the NFKC pre-pass then case-folds, so identifiers compare case-insensitively across answer and evidence.

normalize_identifier(raw: str) -> str

Parameter Type Default Description
raw str The raw identifier literal.

Returns: str — The NFKC-normalized, case-folded identifier.

Function normalize_number

Normalize a numeric/money/percent literal to a canonical float.

Strips currency symbols, percent signs, and thousand separators, resolves a leading sign, then resolves a trailing magnitude suffix (k/M/B, case-insensitive).

normalize_number(raw: str) -> float

Parameter Type Default Description
raw str The raw numeric literal as it appeared in text, e.g. "$1.24M", "1,234,500", "15.3%", or "-15.3%".

Returns: float — The canonical float value, e.g. "$1.24M" -> 1_240_000.0.

Raises:

  • ValueError — If raw does not contain a parseable number.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally