> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aiql.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Extract fields

> Pull specific fields and values out of text with the extract tool

The `extract` tool is the final step of the pipeline. It pulls structured values out of markdown content according to a schema.

## Prerequisites

* An AiQL API key in the `AIQL_API_KEY` environment variable
* Markdown content to extract from, and a schema describing what to pull

## Extract structured data

Send the markdown to extract from and the schema that describes the data. Use the schema from [Shape](/cookbooks/shape), or supply your own. Tool requests authenticate with a Bearer token and do not need a workspace.

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST https://api.aiql.io/extract \
    -H "Authorization: Bearer $AIQL_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "markdown": "# Report\n\nThe markdown content...",
      "schema": {
        "classes": [{"name": "Person", "definition": "An individual human."}],
        "properties": [{"name": "name", "definition": "The person'\''s full name.", "domain": ["Person"]}],
        "relationships": [{"name": "knows", "definition": "One person is acquainted with another.", "domain": ["Person"], "range": ["Person"]}]
      }
    }'
  ```

  ```python Python theme={null}
  import os
  from aiql import AiQL

  client = AiQL(api_key=os.environ["AIQL_API_KEY"])

  records = client.tools.extract(markdown=markdown, schema=schema)
  print(records)
  ```

  ```typescript TypeScript theme={null}
  import { AiQL } from "@aiql.io/sdk";

  const client = new AiQL({ apiKey: process.env.AIQL_API_KEY });

  const records = await client.tools.extract({ markdown, schema });
  console.log(records);
  ```
</CodeGroup>

The `schema` is made of `classes`, `properties`, and `relationships`:

* A **class** has a `name` and a `definition`.
* A **property** has a `name`, a `definition`, and a `domain` (the class or classes it applies to).
* A **relationship** has a `name`, a `definition`, a `domain` (the class or classes it starts from), and a `range` (the class or classes it points to).

The response is a graph of `nodes` and `relationships` pulled from the markdown according to the schema:

* A **node** has a required `id` and `name`, plus a `properties` object of extracted values.
* A **relationship** has an `id`, a `name`, and the `source` and `target` node ids it connects.

## Next step

To run all four steps as one managed job and load the result into a workspace, see [Run a full ingestion](/cookbooks/ingestion).

<Note>
  `extract` is billed at 30 credits per 1,000 words, with a minimum of 1 credit. See [Pricing](/pricing) for details.
</Note>
