Skip to main content

quality_metrics()

Returns a quality score, grade, and noise ratio for a block of text.
from flexorch_audit import quality_metrics

text = """
Invoice Date: 2024-01-15
Vendor: Acme GmbH
Total: €12,500.00
IBAN: DE89 3704 0044 0532 0130 00
"""

metrics = quality_metrics(text)
print(metrics)
# {
#   "score": 88,
#   "grade": "A",
#   "noise_ratio": 0.04,
#   "detected_language": "en"
# }

noise_ratio()

Returns only the noise ratio (0.0–1.0) — the proportion of the text that is non-informative.
from flexorch_audit import noise_ratio

ratio = noise_ratio("### !!! @@@ page 1 of 10 ### !!! ###")
print(ratio)  # 0.82
A noise ratio above 0.20 triggers a quality penalty. Above 0.50, a warning is added to the result.

Grade thresholds

GradeScore
A85–100
B65–84
C45–64
D0–44

estimate_tokens()

Estimate token count before sending to an LLM — no tiktoken required:
from flexorch_audit import estimate_tokens

count = estimate_tokens(text)
print(count)  # 142