Skip to main content
GraphRAG uses prompts to guide LLMs in extracting entities, relationships, and generating summaries. Customizing these prompts for your specific domain can significantly improve the quality and relevance of your knowledge graph.

Why customize prompts?

Default prompts work well for general use cases, but domain-specific customization offers:
  • Better entity recognition - Identify domain-specific entities
  • Improved relationship extraction - Capture industry-specific connections
  • Domain-aware summaries - Generate contextually relevant reports
  • Reduced hallucinations - Focus on relevant information

Prompt tuning methods

GraphRAG offers two approaches to prompt customization:

Auto tuning

Automatically generates domain-adapted prompts using your data

Manual tuning

Manually edit prompts for fine-grained control

Auto prompt tuning

Auto tuning analyzes your input data and generates optimized prompts automatically.
1

Prepare your data

Place your domain-specific documents in the input/ directory:
cp your-documents/*.txt ./input/
2

Run auto tuning

Execute the auto-tuning command:
graphrag prompt-tune \
  --root . \
  --config ./settings.yaml \
  --no-entity-types \
  --output ./prompts
Auto tuning will make several LLM calls to analyze your data. This may take a few minutes and consume API tokens.
3

Review generated prompts

Check the generated prompts in the ./prompts directory:
ls -lh prompts/
You’ll find:
  • entity_extraction.txt - Entity extraction prompt
  • summarize_descriptions.txt - Entity summarization prompt
  • community_report.txt - Community report generation prompt
4

Update configuration

Update settings.yaml to use the custom prompts:
entity_extraction:
  prompt: prompts/entity_extraction.txt

summarize_descriptions:
  prompt: prompts/summarize_descriptions.txt

community_reports:
  prompt: prompts/community_report.txt
5

Re-index with custom prompts

Run indexing again with your tuned prompts:
graphrag index --root .

Manual prompt tuning

For advanced use cases, you can manually edit prompts to have complete control.

Understanding prompt structure

GraphRAG prompts follow a specific structure:
-Goal-
Given a text document, identify all entities and their relationships.

-Steps-
1. Identify all entities in the text
2. For each entity, extract relevant attributes
3. Identify relationships between entities
4. Format the output as specified

-Entity Types-
- PERSON: Human individuals
- ORGANIZATION: Companies, institutions
- LOCATION: Physical or virtual places
- EVENT: Significant occurrences

-Output Format-
Return a JSON object with entities and relationships.

Example: Customizing for medical domain

1

Create custom entity types

Define domain-specific entities for medical documents:
prompts/medical_entities.txt
-Goal-
Extract medical entities and relationships from clinical documents.

-Entity Types-
- PATIENT: Individual receiving medical care
- CONDITION: Medical diagnosis or symptom
- MEDICATION: Drugs or treatments
- PROCEDURE: Medical interventions
- PROVIDER: Healthcare professionals
- FACILITY: Healthcare institutions

-Relationship Types-
- TREATS: Medication treats condition
- DIAGNOSED_WITH: Patient has condition
- PRESCRIBED_BY: Provider prescribes medication
- PERFORMED_AT: Procedure at facility

-Examples-
[Provide domain-specific examples here]
2

Customize community reports

Tailor community summaries for medical insights:
prompts/medical_community_report.txt
-Goal-
Generate a medical community summary highlighting:
- Common conditions and treatments
- Treatment efficacy patterns
- Patient outcome trends
- Provider specializations

-Report Structure-
# Community Medical Summary

## Overview
[Brief description of the medical community]

## Key Conditions
[Most prevalent diagnoses and symptoms]

## Treatment Patterns
[Common medications and procedures]

## Outcomes
[Success rates and patient progress]
3

Update configuration

Reference your custom prompts in settings.yaml:
entity_extraction:
  prompt: prompts/medical_entities.txt
  entity_types: [PATIENT, CONDITION, MEDICATION, PROCEDURE, PROVIDER, FACILITY]

community_reports:
  prompt: prompts/medical_community_report.txt

Domain-specific examples

Best practices

Start with auto tuning

Begin with auto-generated prompts and refine manually as needed

Provide examples

Include domain-specific examples in your prompts for better results

Iterate and test

Test prompts on sample data and refine based on output quality

Keep it focused

Define specific entity types relevant to your domain, avoid being too broad

Testing custom prompts

1

Create test dataset

Use a small, representative sample of your data:
mkdir test_input
cp input/sample*.txt test_input/
2

Run indexing on test data

Configure GraphRAG to use your test directory:
graphrag index --root ./test_workspace
3

Evaluate results

Review the generated entities and relationships:
import pandas as pd

entities = pd.read_parquet('./output/entities.parquet')
print(entities[['name', 'type', 'description']].head(20))

relationships = pd.read_parquet('./output/relationships.parquet')
print(relationships[['source', 'target', 'description']].head(20))
4

Refine and iterate

Based on the results:
  • Add missing entity types
  • Clarify entity definitions
  • Provide more specific examples
  • Adjust relationship types

Advanced techniques

Few-shot learning

Include examples directly in your prompts:
-Examples-
Text: "Dr. Smith prescribed metformin to treat diabetes."
Entities:
- PROVIDER: Dr. Smith
- MEDICATION: metformin
- CONDITION: diabetes
Relationships:
- (Dr. Smith)-[PRESCRIBED]->(metformin)
- (metformin)-[TREATS]->(diabetes)

Chain-of-thought prompting

Guide the LLM through reasoning steps:
-Reasoning Process-
1. First, identify all named entities in the text
2. Then, determine the type of each entity based on context
3. Next, find relationships by analyzing entity interactions
4. Finally, extract supporting evidence for each relationship

Next steps

Prompt tuning guide

Complete guide to prompt tuning

Configuration reference

Full configuration options

Global search notebook

Experiment with search parameters

Use cases

Real-world examples

Build docs developers (and LLMs) love