---
title: "Arabic named entity extraction with an LLM, to JSON | BroadRouter"
description: "Extract Arabic names, organisations, places and Hijri dates to JSON with an LLM: a prompt, span checks that ignore diacritics, date conversion and a scoring script."
url: https://broadrouter.com/blog/arabic-named-entity-extraction-llm/
lang: en
updated: 2026-11-15
publisher: BroadRouter (a BroadNet site); API by BroadNet Inference, https://inference.broadnet.ai
---

# Arabic named entity extraction with an LLM: JSON, dates and checks

By the BroadNet Inference team · 7 min read · Published 2026-11-15

Ask the model to copy each entity exactly as written, with a type from a fixed list, as JSON. Check every entity in code: it must appear in the source once diacritics are stripped and alef forms unified. Convert Hijri dates with a library such as hijridate, not the model. Score a hand-labelled sample with entity-level precision, recall and F1.

## Key takeaways

-   In LAraBench (EACL 2024), zero-shot GPT-4 scored 0.355 macro-F1 on ANERcorp token tagging against 0.886 for a fine-tuned system; 10-shot raised it to 0.451.
-   Extracting a short JSON list of entities is a different task from tagging every token. Test the framing you will ship, on your own text.
-   Match entities after removing tashkeel and tatweel and unifying alef forms, or a name the model copied correctly will look like a hallucination.
-   Let the model read the date; let code convert it. hijridate covers Umm al-Qura dates from 1343 to 1500 AH (1924 to 2077 CE).
-   Public Arabic NER sets exist for news (ANERcorp), Wikipedia (AQMAR), MSA plus dialect (Wojood) and Classical Arabic (CANERCorpus). Their labels rarely match yours.

**On this page**

1.  How well do LLMs do Arabic NER?
2.  Which Arabic NER datasets exist?
3.  What should the prompt ask for?
4.  How do you check entities against the source?
5.  How do you handle Hijri dates?
6.  What about names in Arabizi and mixed text?
7.  How do you score the extractor?
8.  Which BroadNet model should you use?
9.  Where BroadNet Inference fits

Named entity extraction turns a paragraph into records your code can use: who, which organisation, where and when. Arabic adds four problems English pipelines rarely meet: optional diacritics, several spellings of the same letter, names written in Latin letters ([Arabizi](https://broadrouter.com/glossary/arabizi/)), and dates in two calendars. This post builds an extraction step on an OpenAI-compatible LLM that handles each one in code, and a scoring script to tell you whether it works on your text.

For classifying whole messages rather than pulling spans out of them, see [Arabic text classification](https://broadrouter.com/blog/arabic-text-classification-llm/). For the JSON request options themselves, see [JSON mode vs json\_schema](https://broadrouter.com/blog/structured-output-json-schema/).

## How well do LLMs do Arabic NER?

The most relevant public measurement we found is LAraBench (Abdelali et al., EACL 2024), which ran GPT-3.5 and GPT-4 on Arabic NER sets as token-by-token tagging. Macro-F1, higher is better:

| Dataset | GPT-3.5 zero-shot | GPT-4 zero-shot | GPT-4 3-shot | Fine-tuned system cited |
| --- | --- | --- | --- | --- |
| ANERcorp (news) | 0.210 | 0.355 | 0.420 | 0.886 |
| AQMAR (Wikipedia) | 0.230 | 0.365 | 0.390 | 0.690 |
| QASR (transcripts) | 0.208 | 0.504 | n/a | 0.698 |

More examples helped: GPT-4 on ANERcorp rose from 0.355 with no examples to 0.451 with ten. The authors also had to remap tags the model wrote in its own format, such as PER-B for B-PER.

Read this with care. These are 2023 models doing a strict tagging task on benchmark label sets. A current model asked for a short list of people and companies in a support ticket may do much better, or not. The table tells you two things that still hold: an LLM is not automatically a good NER system, and you need your own measurement.

## Which Arabic NER datasets exist?

| Dataset | Text | Size and labels |
| --- | --- | --- |
| [ANERcorp](https://camel.abudhabi.nyu.edu/anercorp/) | News | About 150,000 tokens; person, location, organisation, miscellaneous. CAMeL Lab publishes a standard train/test split |
| [CLEANANERCorp](https://aclanthology.org/2024.osact-1.2/) | ANERcorp, corrected | Fixes annotation errors, missing labels and inconsistencies found in the original |
| [AQMAR](https://www.cs.cmu.edu/~ark/ArabicNER/) | Arabic Wikipedia | 74,000 tokens from 28 articles |
| [Wojood](https://aclanthology.org/2022.lrec-1.387/) | MSA and dialect | About 550,000 tokens, 21 entity types, nested; used in the WojoodNER 2023 shared task |
| [CANERCorpus](https://github.com/RamziSalah/Classical-Arabic-Named-Entity-Recognition-Corpus) | Classical Arabic hadith | More than 7,000 hadiths, 20 types on Islamic topics |

Use them to sanity-check a prompt, not as your acceptance test. Your entity types (customer, product, branch, contract number) will differ from theirs, and their licences differ too. Check each one before commercial use.

## What should the prompt ask for?

Three rules make the output checkable:

1.  **Copy the span exactly.** No translation, no transliteration, no “completing” a first name into a full name. If you need an English spelling, ask for it in a separate field and treat it as unverified.
2.  **A closed type list.** PERSON, ORG, LOCATION, DATE, or your own set. Free-form types can’t be scored.
3.  **Dates as parts, not conversions.** Ask for year, month and day as written, plus the calendar. A trailing هـ marks a Hijri date; م marks Gregorian.

Write the instructions in English or Arabic; [Arabic prompt engineering](https://broadrouter.com/blog/arabic-prompt-engineering/) covers the trade-off. Put the JSON shape in the system prompt and keep it identical across requests so it can be [cached](https://broadrouter.com/glossary/cached-input-tokens/).

## How do you check entities against the source?

The model may return a name the text never mentions, or copy a name correctly but without its diacritics. A plain substring test can’t tell those apart. Normalise both sides first: remove tashkeel and tatweel, unify alef forms, and join عبد ال so عبد الله matches عبدالله. The rules are the same as in [Arabic text normalization for search](https://broadrouter.com/blog/arabic-text-normalization-search/), applied to matching only. Keep the original span for display.

```python
import json, os, re
from hijridate import Hijri
from openai import OpenAI

client = OpenAI(base_url="https://inference.broadnet.ai/v1", api_key=os.environ["BROADNET_API_KEY"])

TYPES = {"PERSON", "ORG", "LOCATION", "DATE"}
SYSTEM = """Extract named entities from the Arabic text. Reply with JSON only:
{"entities": [{"text": "...", "type": "PERSON|ORG|LOCATION|DATE"}],
 "dates": [{"text": "...", "calendar": "hijri|gregorian", "year": 0, "month": 0, "day": 0}]}
Rules: copy "text" exactly as it appears in the input, including any diacritics.
Do not translate, transliterate or complete names. A date followed by هـ is Hijri.
If there are no entities, return empty lists."""

DIACRITICS = re.compile(r"[ً-ٰٟـ]")   # tashkeel, dagger alef, tatweel
def norm(s: str) -> str:
    s = DIACRITICS.sub("", s)
    s = re.sub("[إأآٱ]", "ا", s).replace("ى", "ي").replace("عبد ال", "عبدال")
    return " ".join(s.split())

def validate(source: str, data: dict) -> tuple[list, list]:
    """Keep entities that really occur in the source; report everything else."""
    src, kept, problems = norm(source), [], []
    for e in data.get("entities", []):
        if e.get("type") not in TYPES:
            problems.append(f"unknown type: {e}")
        elif norm(e.get("text", "")) not in src:
            problems.append(f"not in source: {e['text']}")
        else:
            kept.append(e)
    for d in data.get("dates", []):
        if d.get("calendar") == "hijri":
            try:
                d["iso"] = Hijri(d["year"], d["month"], d["day"]).to_gregorian().isoformat()
            except (ValueError, OverflowError) as err:
                problems.append(f"bad Hijri date {d['text']}: {err}")
    return kept, problems

def extract(text: str, model="broadnet/qwen3.8-27b") -> dict:
    r = client.chat.completions.create(
        model=model, max_tokens=2000,
        messages=[{"role": "system", "content": SYSTEM}, {"role": "user", "content": text}])
    data = json.loads(r.choices[0].message.content)
    data["entities"], data["problems"] = validate(text, data)
    return data

text = "التقى خالِد بن سَعِيد مديرةَ شركة النخيل للتقنية في جدة يوم ١٥ جمادى الآخرة ١٤٤٥هـ."
print(json.dumps(extract(text), ensure_ascii=False, indent=1))
```

We ran this against a local mock server (no live API call) whose canned reply added one invented person and one impossible date (month 13). The output kept خالد بن سعيد (the reply dropped the diacritics; the normalised match still found it), شركة النخيل للتقنية and جدة. It converted ١٥ جمادى الآخرة ١٤٤٥هـ to 2023-12-28, and listed two problems: the invented name was “not in source”, and month 13 raised “month must be in 1-12”. The names and company are fictional.

Notes on the code:

-   **`max_tokens=2000`** leaves room for reasoning. BroadNet’s docs say DeepSeek V4.1 Flash, GLM 5.3 and Qwen3.8 27B reason before answering, and that reasoning counts toward `max_tokens`. See [empty responses from reasoning models](https://broadrouter.com/guides/reasoning-tokens-empty-response/).
-   **`json.loads` can fail.** Wrap it, and on failure resend once with the error, as in the [repair loop](https://broadrouter.com/blog/structured-output-json-schema/). On GLM 5.3 and Qwen3.8 27B, which BroadNet documents with structured output, add a `response_format` schema too. Validation stays either way.
-   **Substring matching is deliberately loose.** It confirms the span exists; it does not confirm the type. Types are what the scoring step below measures.

## How do you handle Hijri dates?

Arabic text writes dates many ways: ١٥/٦/١٤٤٥هـ, ١٥ جمادى الآخرة ١٤٤٥, or a Gregorian date with month names that vary by region (نوفمبر in Egypt and the Gulf, تشرين الثاني in the Levant). A model can usually split these into parts, and the code checks the parts. Converting between calendars is arithmetic on a published table, and a model has no reason to get it right.

[hijridate](https://pypi.org/project/hijridate/), formerly hijri-converter, converts using the Umm al-Qura calendar. Its documented range is 1343 to 1500 AH (1 August 1924 to 16 November 2077 CE). Out of range it raises OverflowError; an invalid month or day raises ValueError, which is why the code catches both. Its docs say it is not intended for religious purposes where crescent sighting is preferred, so a date set by sighting can differ from the converted value. Store the date as written next to the converted one.

Eastern Arabic digits need no special handling here: the model returns integers. If you parse dates yourself, map ٠١٢٣٤٥٦٧٨٩ (and the Persian ۰–۹) to 0–9 first.

## What about names in Arabizi and mixed text?

Customer messages often write names in Latin letters: “ana 7a2ool la Mo7ammad bokra”. The exact-span rule still works: the entity text is “Mo7ammad”, and the substring check passes. What fails is matching that record to محمد in your CRM. Do that in a second step: convert the span to Arabic script, as in [handling Arabizi](https://broadrouter.com/blog/arabizi-llm-handling/), then match against your records with the same normalisation. Keep a confidence flag on any record that came through a conversion.

The same applies to English company names inside Arabic sentences, and to Latin spellings of Arabic names (Mohammed, Muhammad, Mohamed). Don’t ask the extraction step to pick one spelling.

## How do you score the extractor?

Label 100 to 200 real samples by hand, with the same type list. Then compare predictions with entity-level exact match on the normalised text and type, and report precision, recall and F1 per type:

```python
from collections import Counter

def score(gold: list[list[dict]], pred: list[list[dict]]) -> dict:
    """Entity-level exact match on (normalised text, type), micro-averaged, plus per type."""
    tp, fp, fn = Counter(), Counter(), Counter()
    for g, p in zip(gold, pred):
        G = Counter((norm(e["text"]), e["type"]) for e in g)
        P = Counter((norm(e["text"]), e["type"]) for e in p)
        for (t, ty), n in (G | P).items():
            hit = min(G[(t, ty)], P[(t, ty)])
            tp[ty] += hit; fp[ty] += P[(t, ty)] - hit; fn[ty] += G[(t, ty)] - hit
    def prf(a, b, c):
        p = a / (a + b) if a + b else 0.0
        r = a / (a + c) if a + c else 0.0
        return {"p": round(p, 3), "r": round(r, 3), "f1": round(2 * p * r / (p + r), 3) if p + r else 0.0}
    out = {ty: prf(tp[ty], fp[ty], fn[ty]) for ty in sorted(tp | fp | fn)}
    out["micro"] = prf(sum(tp.values()), sum(fp.values()), sum(fn.values()))
    return out
```

On a two-sentence toy set (three gold entities; the prediction typed جدة as ORG instead of LOCATION and added one extra place), it printed micro precision 0.5, recall 0.667 and F1 0.571, and LOCATION F1 0. A per-type view shows you where to spend effort: a weak ORG score usually means your type definitions need examples, not a bigger model.

Decide in advance what counts as a match. Exact match is strict: “شركة النخيل” against a gold “شركة النخيل للتقنية” scores as one false positive and one false negative. If partial spans are acceptable for your use, report a second, overlap-based score, but keep the strict one as the headline.

## Which BroadNet model should you use?

All prices are per 1M tokens, from BroadNet’s pricing page.

| Model | Why | Input / output |
| --- | --- | --- |
| [Qwen3.8 27B](https://broadrouter.com/models/qwen3.8-27b/) | Structured output documented; BroadNet reports it tested in Arabic, including Gulf and Egyptian dialect understanding; reads images | $0.175 / $2.17 |
| [GLM 5.3](https://broadrouter.com/models/glm-5.3/) | Structured output documented; 1,048,576-token context for very long documents | $0.78 / $3.46 |
| [Gemma 4 VL 26B](https://broadrouter.com/models/gemma-4-vl-26b/) | Runs on the $5 starting credit; no structured output documented, so validate prompt-only JSON; 32,768-token context | $0.10 / $0.22 |

Run the scoring script on your sample with each candidate and pick on F1 per type and cost, not on the vendor’s description. Arabic usually takes more tokens than English for the same content; [tokens per word in Arabic](https://broadrouter.com/blog/tokens-per-word-arabic-english/) has measured ratios. For entities inside scanned forms or photos, extract from the image directly, as in [reading Arabic invoices with vision](https://broadrouter.com/guides/read-arabic-invoices-with-vision/).

## Where BroadNet Inference fits

BroadRouter is BroadNet’s own site. BroadNet Inference gives you OpenAI-compatible access to the models above with one key, so the code runs with the [OpenAI Python SDK](https://broadrouter.com/guides/openai-python-sdk/) after changing the base URL. Its docs say prompts and answers are not retained after the request, which matters when the text is full of people’s names. It has no dedicated NER endpoint and publishes no Arabic NER benchmark of its own, so measure on your data. If you need a self-hosted tagger for high volume, a fine-tuned model trained on Wojood or your own labels may be cheaper and more consistent than any LLM; the published gap above is the reason to check.

Free tools for this

-   [Arabic token counter](https://broadrouter.com/tools/arabic-token-counter/) Arabic vs English token counts per tokenizer: the "Arabic tax" in tokens and money.
-   [Arabic text normalizer](https://broadrouter.com/tools/arabic-text-normalizer/) Tashkeel, tatweel, alef, ya, ta marbuta, digits and invisible characters, with a matching Python function.
-   [Speech-to-text cost calculator](https://broadrouter.com/tools/speech-to-text-cost-calculator/) Hours, calls or voice notes to a monthly transcription bill, against your current provider.

[All free tools](https://broadrouter.com/tools/)

## Terms in this article

[Token](https://broadrouter.com/glossary/token/)

A token is the unit of text a language model reads and writes: a word, part of a word, a punctuation mark or a byte sequence produced by the model's tokenizer. LLM APIs count, limit and usually bill usage in tokens.

[Named entity recognition (NER)](https://broadrouter.com/glossary/named-entity-recognition/)

Named entity recognition (NER) is the task of finding names in text and labelling each with a type, such as person, organization or location. Classic systems tag every token; LLMs are often asked instead to return a list of entities as JSON, which is then checked against the source.

[Arabic diacritics (tashkeel)](https://broadrouter.com/glossary/arabic-diacritics/)

Arabic diacritics, or tashkeel, are small marks written above or below letters to show short vowels, doubled consonants and the absence of a vowel. They are optional: most Arabic text, including news, omits them, so readers and software infer the vowels from context.

[Arabizi](https://broadrouter.com/glossary/arabizi/)

Arabizi is Arabic written informally in Latin letters, using digits for Arabic sounds with no Latin equivalent, such as 3 for ع. It is common in chat and social media, is mostly dialectal, has no standard spelling, and is often mixed with English or French.

[Structured output](https://broadrouter.com/glossary/structured-output/)

Structured output is an LLM API feature that constrains a model's reply to a format the developer specifies, usually a JSON Schema, so code can parse it reliably. It is stricter than JSON mode, which guarantees valid JSON but not a particular shape.

[Arabic text normalization](https://broadrouter.com/glossary/arabic-text-normalization/)

Arabic text normalization is the step that maps spelling variants of the same word to one form before matching: removing diacritics and tatweel, unifying alef forms, and often mapping ى to ي and ة to ه. It is applied to search keys and evaluation, not to text you display.

[Base URL](https://broadrouter.com/glossary/base-url/)

A base URL is the fixed root address of an API, such as https://api.example.com/v1, that a client puts in front of every endpoint path, such as /chat/completions. In OpenAI-compatible SDKs, changing the base URL, together with the API key and model ID, points the same code at a different provider.

[JSON mode](https://broadrouter.com/glossary/json-mode/)

JSON mode is an LLM API setting, response\_format {"type": "json\_object"} in OpenAI-style APIs, that makes the model's reply valid, parseable JSON. Unlike structured outputs with a JSON Schema, it does not guarantee which keys, types or values the object contains.

## Questions

### Can an LLM do Arabic named entity recognition?

Yes, with checks. Published zero-shot results on token-level Arabic NER trail fine-tuned models by a wide margin, so validate every entity against the source text and score the model on a labelled sample of your own data before you rely on it.

### How do I match Arabic names with and without diacritics?

Normalise both sides before comparing: remove tashkeel (U+064B to U+065F), the dagger alef and tatweel, map إ أ آ ٱ to ا and ى to ي, and collapse spaces. Keep the original text for display; use the normalised form only for matching.

### How do I convert a Hijri date to Gregorian in Python?

Use hijridate (formerly hijri-converter): Hijri(1445, 6, 15).to\_gregorian() returns 2023-12-28. It follows the Umm al-Qura calendar, supports 1343 to 1500 AH, and is not meant for religious dates set by moon sighting.

### Which Arabic NER datasets can I test on?

ANERcorp (news, about 150,000 tokens, four types), AQMAR (74,000 tokens of Wikipedia), Wojood (about 550,000 tokens of MSA and dialect with 21 nested types) and CANERCorpus (Classical Arabic hadith, 20 types). Check each licence, and map their labels to yours.

### Should the model translate or transliterate names?

Not in the extraction step. Ask for the exact source span, so you can verify it. Add a separate field for a Latin spelling if you need one, and treat it as unverified.

## Keep reading

-   [JSON mode vs json\_schema: structured output that holds up](https://broadrouter.com/blog/structured-output-json-schema/)
-   [Arabic text normalization for search and RAG: what to change, what not](https://broadrouter.com/blog/arabic-text-normalization-search/)
-   [Arabizi and LLMs: handling Franco-Arabic with numbers like 3 and 7](https://broadrouter.com/blog/arabizi-llm-handling/)
-   [Arabic text classification with an LLM: sentiment, intent, triage](https://broadrouter.com/blog/arabic-text-classification-llm/)
-   [Arabic prompt engineering: register, RTL, numerals and mixed text](https://broadrouter.com/blog/arabic-prompt-engineering/)
-   [Choosing an LLM API for Arabic: what to test](https://broadrouter.com/blog/choosing-an-llm-for-arabic/)
-   [Arabic grammar and spelling correction with an LLM: a how-to](https://broadrouter.com/blog/arabic-grammar-spelling-correction-llm/)
-   [Add diacritics to Arabic text with an LLM: prompt, checks, DER](https://broadrouter.com/blog/arabic-diacritization-llm/)
-   [Arabic meeting minutes from recordings: an API pipeline](https://broadrouter.com/blog/arabic-meeting-minutes-from-recordings/)
-   [Guide: Read Arabic invoices and receipts with a vision model](https://broadrouter.com/guides/read-arabic-invoices-with-vision/)
-   [Guide: Use the OpenAI Python SDK with BroadNet Inference](https://broadrouter.com/guides/openai-python-sdk/)

Try it on your real workload. New accounts start with $5 of credit for Gemma and transcription. DeepSeek, GLM and Qwen3.8 need a top-up.

[Get started](https://inference.broadnet.ai/account/?utm_source=broadrouter&utm_medium=referral&utm_campaign=blog-arabic-named-entity-extraction-llm&utm_content=page-cta) ·

**Sources**

-   [Abdelali et al., LAraBench: Benchmarking Arabic AI with Large Language Models, EACL 2024, Tables 1 and 5 (checked 2026-11-15)](https://aclanthology.org/2024.eacl-long.30/)
-   [Jarrar, Khalilia and Ghanem, Wojood: Nested Arabic Named Entity Corpus and Recognition using BERT, LREC 2022 (checked 2026-11-15)](https://aclanthology.org/2022.lrec-1.387/)
-   [Jarrar et al., WojoodNER 2023: The First Arabic Named Entity Recognition Shared Task, ArabicNLP 2023 (checked 2026-11-15)](https://aclanthology.org/2023.arabicnlp-1.83/)
-   [CAMeL Lab, ANERcorp download page and train/test split (checked 2026-11-15)](https://camel.abudhabi.nyu.edu/anercorp/)
-   [AlDuwais, Al-Khalifa and AlSalman, CLEANANERCorp: Identifying and Correcting Incorrect Labels in the ANERcorp Dataset, OSACT 2024 (checked 2026-11-15)](https://aclanthology.org/2024.osact-1.2/)
-   [CMU ARK, AQMAR Arabic Wikipedia Named Entity Corpus: 74,000 tokens, 28 articles (checked 2026-11-15)](https://www.cs.cmu.edu/~ark/ArabicNER/)
-   [Salah and Zakaria, Classical Arabic Named Entity Recognition Corpus (CANERCorpus) repository (checked 2026-11-15)](https://github.com/RamziSalah/Classical-Arabic-Named-Entity-Recognition-Corpus)
-   [hijridate on PyPI: Umm al-Qura converter, formerly hijri-converter, 1343 to 1500 AH (checked 2026-11-15)](https://pypi.org/project/hijridate/)
-   [BroadNet Inference API reference: models with structured output, reasoning and max\_tokens (checked 2026-11-15)](https://inference.broadnet.ai/docs?utm_source=broadrouter&utm_medium=referral&utm_campaign=blog-arabic-named-entity-extraction-llm&utm_content=sources)
