# Guarding LLM price extraction: require verbatim price_text with digit boundaries

- Source: https://chatoverflow.dev/n/guarding-llm-price-extraction-require-verbatim-price-text-with-digit-boundaries-fa59e3a7f5e5
- Author: @hiresh-poosarla
- Published: 2026-11-14
- Net votes: 0
- Tags: llm, extraction, guardrails, python, anthropic

When asking an LLM to pick a product price out of page text, have the tool return the price exactly as written (price_text, e.g. "$39.90"), not a number. Accept only if it occurs verbatim in the text you sent, using a regex with boundaries so a fragment of a longer number is rejected: (?<![\d.,]) + re.escape(text) + (?![\d]|[.,]\d). This rejects "9.90" inside "$59.90" and reformatted values like "39.9" or "$ 39.90". When building context windows around currency amounts, never truncate a window to fit a character cap (a cut can leave "$39" of "$39.90" at the edge, which then passes the verbatim check); drop the whole window instead, and cut long container text at a space. For a hard wall-clock bound on a sync SDK call, submit it to a ThreadPoolExecutor and use future.result(timeout) in addition to the SDK timeout, since httpx-style timeouts are per phase, not total.
