Skip to main content
A minimal guide to creating custom tasks and pipelines. The updated example builds a lightweight ingestion object, extracts people with an LLM task, stores the resulting graph nodes, and then visualizes the result. Before you start:
  • Complete Quickstart to understand basic operations
  • Ensure you have LLM Providers configured
  • Have some text data to process

What Custom Tasks and Pipelines Do

  • Define custom processing steps using Task objects
  • Chain multiple operations together in a custom pipeline
  • Use LLMs to extract structured data from text
  • Insert structured data directly into the knowledge graph
  • Control the entire data processing workflow

Code in Action

Step 1: Define Your Pipeline Models

PersonLLM and PeopleLLM describe the structured output the LLM should return. Person is the graph-ready DataPoint, and LightweightData gives the pipeline a simple ingestion object with a stable ID and text field.

Step 2: Create Your Custom Task

This task uses the LLM to extract lightweight people records, then resolves those names into graph-ready Person objects with knows relationships.
acreate_structured_output is backend-agnostic (BAML or LiteLLM+Instructor). Configure it through STRUCTURED_OUTPUT_FRAMEWORK in .env.

Step 3: Build and Run Your Pipeline

The custom pipeline inserts the extracted Person nodes directly into the graph. The follow-up cognify() call builds the rest of Cognee’s retrieval stack on top of that stored graph data.
If a task raises an exception while processing a data item, the pipeline run yields a PipelineRunErrored status and then re-raises the original exception to the caller, instead of failing silently. Wrap your pipeline run in try/except so you can handle the propagated error.

Step 4: Visualize the Result

The example writes an HTML graph visualization so you can inspect the entities and inferred knows edges produced by the custom pipeline.

Use Cases

This approach is particularly useful when you need to:
  • Extract structured data from unstructured text
  • Process data through multiple custom steps
  • Control the entire data processing workflow
  • Combine LLM extraction with programmatic data insertion
  • Build complex data processing pipelines

Additional information

If you already have nodes and edges — exported from another graph database, or stored as JSON/CSV — you don’t need the LLM to re-extract them. Map your data to DataPoint models and store it directly with add_data_points. Because run_custom_pipeline can work with already-built graphs, this recreates your graph deterministically (no LLM extraction step):
  • Nodes become DataPoint subclasses, one per entity type.
  • Edges are expressed as nested DataPoint fields — the field name becomes the relationship label (e.g. employees: list[Person] creates employees edges).
  • Typed or weighted edges use the Edge model: declare the field as SkipValidation[Any] and set values to (Edge(relationship_type="manager", weight=0.9), node) tuples.
For deterministic re-imports, either map stable source IDs into each DataPoint’s id field or configure identity_fields as shown above. Reusing the same node id updates the existing node instead of creating a duplicate. For a complete example that loads nodes and edges from JSON files, see the organizational hierarchy pipeline on GitHub.

Additional examples

Additional examples about custom tasks and pipelines are available on our github.

Full Example

This updated example uses a lightweight ingestion object, a custom extraction task, and a visualization step. In practice, you can create larger pipelines with additional transforms and storage stages.

Custom Data Models

Learn about custom data models

Low-Level LLM

Learn about direct LLM interaction

Core Concepts

Understand knowledge graph fundamentals