JSON SCHEMA GATE · ZERO HALLUCINATION

Strict JSON Schema Validation Gate: Stop Dirty HTML & Missing Fields Before Ingestion

Target Query: strict json schema validation gate web scraping rag · Category: Data Quality · Verified Rate: $0.015/hit ($0 on miss) · Updated: 2026-12-02

Direct Answer: Silent schema drift is the #1 killer of production RAG indexes and automated data pipelines: a publisher renames a CSS class, your scraper inserts null prices into Postgres or embeds a '404' string into a vector store, and you still pay full API credits. Scrape-Anything runs a pure-stdlib strict JSON Schema validator on every extraction before billing—returning exact JSON path errors (`validation_errors`) and `billed_micros = 0` whenever your contract is violated.

Engineering Mechanics & Deterministic Guardrails

Supported JSON Schema Validation Keywords in `src/schema_validator.py`

Keyword GroupSupported KeywordsTypical Extraction GuardOn Violation
Structure & Types`type`, `required`, `properties`, `additionalProperties`Guarantee every required column exists with exact type`schema_valid: false`, `$0`
String Constraints`minLength`, `maxLength`, `pattern`, `enum`Reject empty titles, verify ISO dates/currency codes`schema_valid: false`, `$0`
Numeric Bounds`minimum`, `maximum`Reject negative prices or zero-dollar parsing bugs`schema_valid: false`, `$0`
Array Contracts`items`, `minItems`, `maxItems`Require `>= 1` table rows or JSON-LD objects`schema_valid: false`, `$0`
Polymorphic Unions`anyOf`, `oneOf`Accept either single `Offer` or `AggregateOffer` schema`schema_valid: false`, `$0`
Scrape-Anything Zero-Charge Guardrail Disposition Matrix (% of Unit Rate Billed) Verified Schema-Passing Hit (New) 100% ($0.015) Cross-Tenant Archive Cache Hit 100% ($0.015) Same-Tenant Archive Cache Refresh 10% ($0.0015) Cloudflare / CAPTCHA Fake-200 0% ($0.00) JSON Schema Validation Mismatch 0% ($0.00) SSRF Loopback / Metadata (HTTP 422) 0% ($0.00) Encrypted PDF or Blank SPA Shell 0% ($0.00)

Strict Nested RAG Document Contract Example

{
  "type": "object",
  "additionalProperties": true,
  "required": [
    "title",
    "headings"
  ],
  "properties": {
    "title": {
      "type": "string",
      "minLength": 4,
      "maxLength": 240
    },
    "headings": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "string",
        "minLength": 2
      }
    }
  }
}

Any extracted payload violating required keys, types, bounds, or regex patterns returns schema_valid: false, exact validation_errors, and billed_micros: 0.

Executable REST, Remote /mcp & treg hub Snippets

curl -fsSL -X POST "https://scrape.fastmesh.dev/v1/extract" \
  -H "Content-Type: application/json" \
  -d '{
    "content_text": "<html><head><title>API Docs</title></head><body><h1>Endpoints</h1><p>Verified output.</p></body></html>",
    "json_schema": {
      "type": "object",
      "required": ["title", "nonexistent_mandatory_field"],
      "properties": {
        "title": {"type": "string"},
        "nonexistent_mandatory_field": {"type": "number", "minimum": 1}
      }
    }
  }'

# Schema failure above returns schema_valid: false, detailed validation_errors, and billed_micros: 0
treg call scrape-anything-verified-extract --data '{"mode":"extract","content_text":"<html><title>Test</title></html>","json_schema":{"type":"object","required":["missing_key"]}}'

Hard guarantee: fake-200 CAPTCHA/Turnstile shells, login walls, encrypted PDFs, empty results, schema mismatches, and SSRF HTTP 422 blocks always return billed_micros: 0.

Test Schema-Validated Extraction Live in 5 Seconds

Paste any public URL, HTML table, JSON-LD, CSV, or fake-200 shell at scrape.fastmesh.dev or top up once with never-expiring Creem prepaid credits ($15 Starter / $59 Growth / $199 Scale — $0/mo recurring).

Frequently Asked Questions

Do I have to pass a `json_schema` on every call?

No. `json_schema` is optional—when omitted, Scrape-Anything still enforces anti-fake-200 detection and non-empty extraction before billing. Passing `json_schema` adds strict domain-level contract gating.

How does `schema_validator.py` report nested array errors?

Every mismatch returns exact path strings in `validation_errors` (such as `$.tables[0].rows[3].price: expected number, got str`) so engineers can pinpoint layout drift immediately.

Does a schema-failing extraction deduct from my Creem credit balance?

Never. `billed_micros` is strictly `0` and `CreemCreditLedger.debit_verified` refuses to mutate balances on zero-billed responses.

Related Structured Extraction Guides

Explore all 32 Scrape-Anything Technical Guides or inspect the machine-readable llms.txt index.