Named Entity Extraction Prompts
Extracting names, dates, locations, and custom entities from unstructured text.
What Is Named Entity Extraction?
Named entity extraction (NER) is the task of identifying and categorizing specific real-world entities mentioned in text. Traditional NLP uses statistical models for NER; LLMs can do it with a well-designed prompt.
Common entity types:
- PERSON: People's names (Elon Musk, Dr. Jane Smith)
- ORG: Companies and organizations (Apple, WHO)
- DATE: Dates and time expressions (January 15, last Tuesday, Q3 2024)
- LOCATION: Places (New York, the Amazon River)
- MONEY: Financial figures ($4.2 billion)
Basic NER Prompt
The simplest NER prompt asks for all entities in a specific format:
import anthropic, json
client = anthropic.Anthropic(api_key='YOUR_API_KEY')
text = 'Apple CEO Tim Cook met with European Commission President Ursula von der Leyen in Brussels on March 15, 2025 to discuss the Digital Markets Act.'
prompt = f'''
Extract all named entities from the text below.
Return ONLY a JSON object with no other text:
{{
"people": ["string"],
"organizations": ["string"],
"locations": ["string"],
"dates": ["string"]
}}
Text: {text}
'''
r = client.messages.create(
model='claude-opus-4-5', max_tokens=300,
messages=[{'role': 'user', 'content': prompt}]
)
print(json.loads(r.content[0].text))All lessons in this course
- Named Entity Extraction Prompts
- Schema-Driven Data Extraction
- LLM as Text Classifier
- Confidence and Uncertainty in Classification