By Sagar Shankaran, Founder of CallSphere
Learn how to implement Named Entity Recognition in AI agent pipelines using spaCy and LLMs, covering entity types, custom entity training, and real-time extraction strategies.
Key takeaways
When an AI agent receives a message like "Schedule a meeting with Sarah Chen at the Austin office next Tuesday," it must extract three distinct pieces of structured information: a person (Sarah Chen), a location (Austin office), and a date (next Tuesday). Named Entity Recognition (NER) is the NLP technique that performs this extraction automatically.
Without NER, an agent would have to rely entirely on the LLM to parse every incoming message from scratch. While LLMs are capable of entity extraction, dedicated NER pipelines are faster, cheaper, and more predictable for high-volume workloads. The best agent architectures combine both approaches — fast NER for common entities and LLM fallback for ambiguous cases.
The standard NER taxonomy covers these categories:
flowchart LR
CALLER(["Client"])
subgraph TEL["Telephony"]
SIP["Twilio SIP and PSTN"]
end
subgraph BRAIN["Salon AI Agent"]
STT["Streaming STT<br/>Deepgram or Whisper"]
NLU{"Intent and<br/>Entity Extraction"}
TOOLS["Tool Calls"]
TTS["Streaming TTS<br/>ElevenLabs or Rime"]
end
subgraph DATA["Live Data Plane"]
CRM[("CRM and Notes")]
CAL[("Calendar and<br/>Schedule")]
KB[("Knowledge Base<br/>and Policies")]
end
subgraph OUT["Outcomes"]
O1(["Appointment booked"])
O2(["Reschedule completed"])
O3(["Stylist handoff"])
end
CALLER --> SIP --> STT --> NLU
NLU -->|Lookup| TOOLS
TOOLS <--> CRM
TOOLS <--> CAL
TOOLS <--> KB
NLU --> TTS --> SIP --> CALLER
NLU -->|Resolved| O1
NLU -->|Schedule| O2
NLU -->|Escalate| O3
style CALLER fill:#f1f5f9,stroke:#64748b,color:#0f172a
style NLU fill:#4f46e5,stroke:#4338ca,color:#fff
style O1 fill:#059669,stroke:#047857,color:#fff
style O2 fill:#0ea5e9,stroke:#0369a1,color:#fff
style O3 fill:#f59e0b,stroke:#d97706,color:#1f2937
Most pre-trained NER models handle these out of the box. Custom entities — like internal project names, medical codes, or proprietary terms — require additional training.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent in your browser — 60 seconds, no signup.
spaCy provides production-grade NER that runs in milliseconds per document. Here is a complete extraction pipeline.
import spacy
nlp = spacy.load("en_core_web_trf") # Transformer-based model
def extract_entities(text: str) -> dict[str, list[str]]:
"""Extract named entities grouped by type."""
doc = nlp(text)
entities: dict[str, list[str]] = {}
for ent in doc.ents:
if ent.label_ not in entities:
entities[ent.label_] = []
if ent.text not in entities[ent.label_]:
entities[ent.label_].append(ent.text)
return entities
message = "Tell John at Microsoft to review the Q3 report by March 20th."
result = extract_entities(message)
# {'PERSON': ['John'], 'ORG': ['Microsoft'], 'DATE': ['Q3', 'March 20th']}
When your agent operates in a specialized domain, you need custom entity types. Here is how to train spaCy to recognize a custom PRODUCT_CODE entity.
import spacy
from spacy.training import Example
import random
nlp = spacy.blank("en")
ner = nlp.add_pipe("ner")
ner.add_label("PRODUCT_CODE")
train_data = [
("Order SKU-4829 immediately", {"entities": [(6, 14, "PRODUCT_CODE")]}),
("Check stock for SKU-1100", {"entities": [(16, 24, "PRODUCT_CODE")]}),
("We need SKU-7753 and SKU-2201", {
"entities": [(8, 16, "PRODUCT_CODE"), (21, 29, "PRODUCT_CODE")]
}),
]
optimizer = nlp.begin_training()
for epoch in range(30):
random.shuffle(train_data)
for text, annotations in train_data:
example = Example.from_dict(nlp.make_doc(text), annotations)
nlp.update([example], sgd=optimizer)
doc = nlp("Ship SKU-9981 to warehouse B")
for ent in doc.ents:
print(f"{ent.text} -> {ent.label_}")
# SKU-9981 -> PRODUCT_CODE
For ambiguous text or zero-shot entity types, LLMs provide flexible extraction without training data.
import openai
def llm_extract_entities(text: str, entity_types: list[str]) -> dict:
"""Use an LLM for zero-shot entity extraction."""
prompt = f"""Extract the following entity types from the text.
Return JSON only. Entity types: {', '.join(entity_types)}
Text: {text}"""
response = openai.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": prompt}],
response_format={"type": "json_object"},
temperature=0,
)
return response.choices[0].message.content
result = llm_extract_entities(
"Dr. Amara Osei from Nairobi General prescribed amoxicillin 500mg",
["PERSON", "FACILITY", "MEDICATION", "DOSAGE"]
)
The most effective pattern is a two-tier approach: fast spaCy extraction first, with LLM fallback for unrecognized patterns.
Still reading? Stop comparing — try CallSphere live.
CallSphere ships complete AI voice agents per industry — 14 tools for healthcare, 10 agents for real estate, 4 specialists for salons. See how it actually handles a call before you book a demo.
class NERProcessor:
def __init__(self):
self.nlp = spacy.load("en_core_web_sm")
self.confidence_threshold = 0.85
def process(self, text: str) -> dict:
doc = self.nlp(text)
entities = {}
low_confidence = []
for ent in doc.ents:
if ent.kb_id_ and float(ent.kb_id_) < self.confidence_threshold:
low_confidence.append(ent.text)
else:
entities.setdefault(ent.label_, []).append(ent.text)
return {
"entities": entities,
"needs_llm_review": low_confidence,
}
Use spaCy for high-throughput scenarios where you need consistent, fast extraction of standard entity types. Use LLM-based extraction when you need zero-shot recognition of novel entity types, when the text is highly ambiguous, or when you cannot invest in training data for a custom model.
spaCy handles multi-token entities natively through its span-based architecture. During training, define entity boundaries using character offsets that encompass the full span. For special characters like hyphens or periods in entity names, ensure your tokenizer does not split them incorrectly by adding custom tokenization rules.
Yes. A common pattern is to run a general-purpose model for standard entities (PERSON, ORG, GPE) and a domain-specific model for specialized entities (MEDICATION, LEGAL_CLAUSE). Merge the results and use a deduplication step to handle overlapping spans, keeping the prediction with higher confidence.
#NER #NLP #SpaCy #EntityExtraction #Python #AIAgents #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
A founder's guide to the personal AI assistant market: best AI assistant apps, business-grade options, and how CallSphere's voice agent fits in.
A founder's guide to free AI agents, low-code AI agent builders, and how to know when you should pay for a real platform like CallSphere.
Graphiti is the open-source temporal knowledge graph for AI agents in 2026. Learn how bi-temporal memory beats vector RAG for voice agents and long-running LLMs.
Chatbot app vs ChatGPT in 2026: a founder's clear take on the difference, when to use which, and how a real AI chatbot app development works.
How we built a fault-tolerant HVAC emergency triage and tech-dispatch platform on Kubernetes — three-tier CQRS, 11 micro-agents on the OpenAI Agents SDK + LangGraph, NATS JetStream, DTMF/SMS/WebSocket acceptance, circuit breakers, and an evaluation pipeline that catches regressions before they wake a tech at 3 AM.
Head-to-head: OpenAI Frontier and Anthropic's managed agent stack — strengths, fit, and what each means for enterprise AI voice and chat deployment.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI