Download the PHP package watheqalshowaiter/quran-validator without Composer
On this page you can find all versions of the php package watheqalshowaiter/quran-validator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download watheqalshowaiter/quran-validator
More information about watheqalshowaiter/quran-validator
Files in watheqalshowaiter/quran-validator
Package quran-validator
Short Description Validate Quran quotations, references, ranges, and tagged content.
License MIT
Informations about the package quran-validator
Quran Validator for PHP
Validate and verify Quranic verses in LLM-generated text with high accuracy for PHP 8.1+.
This project is a PHP port of the original quran-validator.
The Problem
LLMs can misquote Quranic verses—subtly changing words, missing diacritics, or combining verses incorrectly. This library provides:
- System prompts that instruct LLMs to tag Quran quotes in a parseable format
- Post-processing that validates tagged quotes against the authentic Quran database
- Auto-correction that fixes imprecise quotes using the authentic text
- Detection of untagged Arabic text that might be Quran verses
Features
- LLM Integration: System prompts and post-processing for complete LLM pipelines
- Multi-tier Matching: Exact and normalized matching with Uthmani script support
- Auto-Correction: Replace valid imprecise quotes with canonical text
- Arabic Normalization: Handle diacritics, alef variants, alef wasla, and more
- Fabrication Detection: Identify words that do not occur in the Quran
- Full Quran Database: All 6,236 verses bundled
- Minimal Dependencies: Runtime polyfills for Unicode normalization and multibyte strings
- Typed API: Strict types, typed value objects, and PHPStan analysis
Installation
Quick Start: LLM Integration
Step 1: Add the System Prompt
Step 2: Process the LLM Response
Step 3: Handle Warnings
Direct Validation API
Validate Against a Specific Reference
Verse Range Support
The processor accepts both single references and consecutive verse ranges:
Fabrication Detection
Identify words that do not occur in the Quran:
System Prompt Formats
LLM Integration Options
Supported tag formats are xml, markdown, and bracket.
Detection Methods
LlmIntegration reports how each quotation was found:
| Method | Description | When used |
|---|---|---|
tagged |
XML, Markdown, bracket, or inline reference | Checked first |
contextual |
Arabic after phrases such as “Allah says” or “in the Quran” | After tagged quotes |
fuzzy |
Untagged Arabic that validates as a complete Quran verse | When scanUntagged is enabled |
Quick Validation
Verse Lookup and Search
Arabic Text Utilities
End-to-End Processing
The package is LLM-provider agnostic. Pass the generated response through the processor before displaying or storing it:
Match Types
| Type | Description |
|---|---|
exact |
Perfect character-by-character match |
normalized |
Match after Arabic normalization |
none |
No match found |
Development
QuranValidator.com
quranvalidator.com is a live service built by the original author of Quran Validator, using the JavaScript version. It evaluates how well multiple LLMs handle Quran quotations—including textual accuracy and reference correctness—and publishes the results in a transparent leaderboard.
Data Source
Uses Quranic data from QUL (Quranic Universal Library) by Tarteel AI:
- Uthmani Script: Arabic text with full diacritics
- Imlaei Simple: Simplified Arabic used for matching
| Total verses | 6,236 |
| Total surahs | 114 |
| Uthmani source | QUL Uthmani, ayah by ayah |
| Simple source | QUL Imlaei Simple |
| Encoding | UTF-8 |
Credits
- Tarteel AI for creating and maintaining QUL
- QUL for its Quranic resources
- Yazin Alirhayim for the original Quran Validator
Contributing
Contributions are welcome. Run the development commands above before submitting a pull request, and include tests for changes to normalization, matching, references, or quote parsing.
License and Data
The PHP source is MIT licensed; see DATASET-LICENSE.md. Do not assume the source-code license covers the dataset.
All versions of quran-validator with dependencies
symfony/polyfill-intl-normalizer Version ^1.38
symfony/polyfill-mbstring Version ^1.38