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

# Custom Prompts

> Step-by-step guide to using custom prompts to control graph extraction

A minimal guide to shaping graph extraction with a custom LLM prompt. You'll pass your prompt via `custom_prompt` to `cognee.remember()` to control entity types, relationship labels, and extraction rules.

<Tip>
  For the built-in graph extraction prompts selected through `GRAPH_PROMPT_PATH`, see [Cognify](/core-concepts/main-operations/legacy-operations/cognify).
</Tip>

**Before you start:**

* Complete [Quickstart](getting-started/quickstart) to understand basic operations
* Ensure you have [LLM Providers](setup-configuration/llm-providers) configured
* Have some text or files to process

## Code in Action

### Step 1: Write a Custom Prompt

```python theme={null}
custom_prompt = """
Extract only people and cities as entities.
Connect people to cities with the relationship "lives_in".
Ignore all other entities.
"""
```

The custom prompt overrides the default system prompt used during entity/relationship extraction. It constrains node types, enforces relationship naming, and reduces noise.

<Note>
  `custom_prompt` is ignored when `temporal_cognify=True`.
</Note>

### Step 2: Remember with Your Custom Prompt

```python theme={null}
await cognee.forget(everything=True)
await cognee.remember(
    [
        "Alice moved to Paris in 2010, while Bob has always lived in New York.",
        "Andreas was born in Venice, but later settled in Lisbon.",
        "Diana and Tom were born and raised in Helsinki. Diana currently resides in Berlin, while Tom never moved.",
    ],
    custom_prompt=custom_prompt,
    self_improvement=False,
)
```

This resets the local state and then uses `remember()` to ingest the text and build the graph in one pass. The same approach works with multiple documents, files, or entire datasets.

### Step 3: Ask Questions

```python theme={null}
res = await cognee.recall(
    query_type=SearchType.GRAPH_COMPLETION,
    query_text="Where does Alice live?",
)
```

Use `cognee.recall(...)` with `SearchType.GRAPH_COMPLETION` to get answers that leverage your custom extraction rules.

## `custom_prompt` vs `system_prompt`: which prompt goes where

Cognee uses **two distinct prompts at two different stages**, and they are not interchangeable. Passing one where the other is expected will silently have no effect.

<Tabs>
  <Tab title="Cognee v1.0">
    | Operation                                   | Prompt parameter                          | What it influences                                                                                                                                                                                                                                                                 | Stage       |
    | ------------------------------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
    | [`cognee.remember()`](/python-api/remember) | `custom_prompt`                           | Entity & relationship extraction — `remember()` runs `add()` + `cognify()` under the hood, so this overrides the graph extraction prompt used during graph build.                                                                                                                  | Graph build |
    | [`cognee.recall()`](/python-api/recall)     | `system_prompt` (or `system_prompt_path`) | Answer generation — instructs the LLM how to compose the final answer from retrieved context. Only applies to completion-style retrieval (`GRAPH_COMPLETION`, `RAG_COMPLETION`, `TRIPLET_COMPLETION`, etc.); ignored by `only_context=True` and by non-completion retrieval paths. | Query time  |
  </Tab>

  <Tab title="Legacy">
    | Operation                                 | Prompt parameter                          | What it influences                                                                                                                                                                                                     | Stage       |
    | ----------------------------------------- | ----------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
    | [`cognee.add()`](/python-api/add)         | *none*                                    | — (pure ingestion; no LLM call)                                                                                                                                                                                        | Ingestion   |
    | [`cognee.cognify()`](/python-api/cognify) | `custom_prompt`                           | Entity & relationship extraction — overrides the default graph extraction prompt (see [`GRAPH_PROMPT_PATH`](/core-concepts/main-operations/legacy-operations/cognify#default-extraction-prompts))                      | Graph build |
    | [`cognee.search()`](/python-api/search)   | `system_prompt` (or `system_prompt_path`) | Answer generation — instructs the LLM how to compose the final answer from retrieved context. Only applies to completion-style search types; ignored by `CHUNKS`, `SUMMARIES`, `CYPHER`, and when `only_context=True`. | Query time  |
  </Tab>
</Tabs>

## Additional examples

Additional examples about Custom prompts are available on our [github](https://github.com/topoteretes/cognee/tree/main/examples/guides).

## Full Example

<Accordion title="Latest guide">
  ```python theme={null}
  import asyncio
  import cognee
  from cognee.api.v1.search import SearchType

  custom_prompt = """
  Extract only people and cities as entities.
  Connect people to cities with the relationship "lives_in".
  Ignore all other entities.
  """

  async def main():
      await cognee.forget(everything=True)
      await cognee.remember(
          [
              "Alice moved to Paris in 2010, while Bob has always lived in New York.",
              "Andreas was born in Venice, but later settled in Lisbon.",
              "Diana and Tom were born and raised in Helsinki. Diana currently resides in Berlin, while Tom never moved.",
          ],
          custom_prompt=custom_prompt,
          self_improvement=False,
      )

      res = await cognee.recall(
          query_type=SearchType.GRAPH_COMPLETION,
          query_text="Where does Alice live?",
      )
      print(res)

  if __name__ == "__main__":
      asyncio.run(main())
  ```
</Accordion>

<Accordion title="Legacy guide">
  ```python theme={null}
  import asyncio
  import cognee
  from cognee.api.v1.search import SearchType

  custom_prompt = """
  Extract only people and cities as entities.
  Connect people to cities with the relationship "lives_in".
  Ignore all other entities.
  """

  async def main():
      await cognee.add([
          "Alice moved to Paris in 2010, while Bob has always lived in New York.",
          "Andreas was born in Venice, but later settled in Lisbon.",
          "Diana and Tom were born and raised in Helsingy. Diana currently resides in Berlin, while Tom never moved."
      ])
      await cognee.cognify(custom_prompt=custom_prompt)

      res = await cognee.recall(
          query_type=SearchType.GRAPH_COMPLETION,
          query_text="Where does Alice live?",
      )
      print(res)

  if __name__ == "__main__":
      asyncio.run(main())
  ```
</Accordion>

<Note>
  This simple example uses a few strings for demonstration. In practice, you can add multiple documents, files, or entire datasets - the custom prompt processing works the same way across all your data.
</Note>

<Tip>
  If you are running Cognee as a server and want to infer a schema or generate a prompt through HTTP instead of writing it by hand, see the **LLM Utility Endpoints** examples in [Deploy REST API Server](/guides/deploy-rest-api-server#llm-utility-endpoints).
</Tip>

<Columns cols={3}>
  <Card title="Core Concepts" icon="brain" href="/core-concepts/overview">
    Understand knowledge graph fundamentals
  </Card>

  <Card title="Ontology Quickstart" icon="git-branch" href="/guides/ontology-support">
    Learn about ontology integration
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/introduction">
    Explore API endpoints
  </Card>
</Columns>
