---
title: "Extract named entities from text"
description: "Identify and extract people, organizations, locations, dates, and other entities from text using LLMs."
url: "https://www.pixeltable.com/notebooks/text-extract-entities"
updated: "2026-04-10"
---

# Extract named entities from text

Identify and extract people, organizations, locations, dates, and other entities from text using LLMs.

- **Type:** Notebook
- **Group:** Text

## How it works

You use structured output to get entities in a consistent JSON format. The entities are stored as JSON columns that you can query and filter.

## What it covers

- Extract entities as structured JSON
- Use OpenAI's structured output for reliable parsing
- Access extracted entities as queryable columns

## What it uses

- **Install:** `pip install pixeltable openai`
- **Environment variables it names:** `OPENAI_API_KEY`
- **Pixeltable calls:** `openai.chat_completions()`, `pxt.create_table()`, `add_computed_column()`, `insert()`

## A look at the code

```python
# Add entity extraction column
extraction_prompt = (
    'Extract all named entities from the following text:\n\n'
    + articles.content
)

articles.add_computed_column(
    extraction_response=chat_completions(
        messages=[{'role': 'user', 'content': extraction_prompt}],
        model='gpt-4o-mini',
        model_kwargs={'response_format': entity_schema},
    )
)
```

## Open it

- **Open in Colab:** https://colab.research.google.com/github/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/text/text-extract-entities.ipynb
- **Docs page:** https://docs.pixeltable.com/howto/cookbooks/text/text-extract-entities
- **Source on GitHub:** https://github.com/pixeltable/pixeltable/blob/release/docs/release/howto/cookbooks/text/text-extract-entities.ipynb
