Back to docs
Recipe

Named entity recognition

Extract structured entities — people, organizations, locations, dates — from unstructured text using Meridian's schema-guided extraction. This recipe shows the minimal setup, a working call against azure/model-router, and how to validate output before downstream use.

1.Pick a model and define the schema

For most NER workloads, azure/model-router is the right default — it adaptively routes between gpt-5-mini and larger Azure deployments based on input complexity. Define entities as an array with text, type, and character offsets so you can highlight matches in the source string.

2.Call extract with your schema

The SDK handles JSON-mode coercion, retry on malformed output, and token accounting. You pay only for the underlying Azure deployment plus Meridian's 20% markup.

import { Meridian } from "@meridian/sdk";

const client = new Meridian({
  apiKey: process.env.MERIDIAN_API_KEY,
});

const text = `Tim Cook announced that Apple will open a new
campus in Austin, Texas on January 15, 2027.`;

const result = await client.extract({
  model: "azure/model-router",
  input: text,
  schema: {
    entities: [
      {
        text: "string",
        type: "PERSON | ORG | LOCATION | DATE",
        start: "number",
        end: "number",
      },
    ],
  },
});

for (const entity of result.entities) {
  console.log(`${entity.type}: ${entity.text}`);
}
// PERSON: Tim Cook
// ORG: Apple
// LOCATION: Austin, Texas
// DATE: January 15, 2027

3.Validate before persisting

Schema-guided output is not a contract. Treat the response as untrusted: verify start and end fall inside the input length, that text matches the substring at those offsets, and that type is one of your allowed enum values. Drop or flag malformed entries before writing to your search index or knowledge graph.

Next steps

Combine NER with embedding search to build entity-linked retrieval, or pipe extracted entities into a structured outputs recipe to populate a database table directly.