Skip to content

Check Lore Consistency

POST
/api/agents/lorekeeper/check-consistency

Comprehensive lore consistency check via LoreKeeper agent with full document analysis.

Analyzes document content for lore inconsistencies, character contradictions, timeline conflicts, and cross-document coherence. Supports both ad-hoc content analysis and tracked document validation with detailed per-document and cross-document issue reporting.

Args: request: FastAPI Request object for service injection context request_data: Consistency check request with documents and analysis options

Returns: ConsistencyCheckResponse: Comprehensive consistency analysis with scores, issues, and suggestions

Raises: HTTPException: If service is unavailable or analysis fails

Note: Uses new service registry pattern with clean dependency injection and automatic fallback handling for service unavailability. Extracts content from DocumentContent objects and provides rich contextual analysis with actionable recommendations.

LorekeeperConsistencyCheckRequest

Comprehensive lore consistency check request.

Validates lore consistency across documents with full context support. Accepts document content with optional IDs, paths, and metadata for maximum flexibility and comprehensive analysis.

Fields: documents: List of DocumentContent objects to check (REQUIRED, min 1) project_type: Project type for lore rules (OPTIONAL, default: “worldbuilding”) check_depth: Analysis depth level (OPTIONAL, default: “moderate”) include_suggestions: Include fix suggestions (OPTIONAL, default: True) compare_against_canon: Compare against specific canon (OPTIONAL) cross_reference: Check consistency across all docs (OPTIONAL, default: True)

JSON Example: { “documents”: [ { “content”: “Arasai fought alongside Erebos…”, “document_id”: “doc_123”, “title”: “Chapter 1” } ], “project_type”: “worldbuilding”, “check_depth”: “deep”, “include_suggestions”: true, “cross_reference”: true }

Used By: - POST /api/agents/lorekeeper/check-consistency - Lore consistency validation UI - Document validation workflows

object
documents
required
Documents

Documents to check with full context

Array<object>
>= 1 items
DocumentContent

Complete document context for lore consistency checking.

Provides rich document context including content, identifiers, and metadata. Supports flexible usage: content-only for ad-hoc analysis OR complete context with IDs, paths, and metadata for tracked documents.

Fields: content: Document content to analyze (REQUIRED) document_id: Source document ID from database (OPTIONAL) path: File path or document location (OPTIONAL) title: Document title for reporting (OPTIONAL) document_type: Type of document (OPTIONAL) project: Project/world the document belongs to (OPTIONAL)

JSON Example: { “content”: “Arasai wielded the Sword of Fate…”, “document_id”: “doc_123”, “path”: “documents/chapter_01.md”, “title”: “Chapter 1: The Beginning”, “document_type”: “story”, “project”: “my_project” }

Used By: - LoreKeeper consistency checking - Document analysis workflows - Cross-reference validation

object
content
required
Content

Document content to analyze for lore consistency

string
documentId
Any of:
string
path
Any of:
string
title
Any of:
string
documentType
Any of:
string
project
Any of:
string
projectType
Projecttype

Project type for lore rules (worldbuilding, custom, generic)

string
default: worldbuilding
checkDepth
Checkdepth

Analysis depth: minor, moderate, strict, deep. Legacy name kept for back-compat — new clients should send strictness on the unified off | low | medium | high scale instead. When both are sent, strictness wins.

string
default: moderate
strictness
Any of:
string
Allowed values: off low medium high
includeSuggestions
Includesuggestions

Include fix suggestions for inconsistencies

boolean
default: true
compareAgainstCanon
Any of:
string
crossReference
Crossreference

Check consistency across all provided documents

boolean
default: true
scopeKind
Scopekind

M8: which scope to run the DE Lorekeeper handler against. document (default) matches the pre-M8 behavior; the other kinds let callers trigger broader scans without splitting the request.

string
default: document
Allowed values: project document scene chapter manuscript

Successful Response

ConsistencyCheckResponse

Lore consistency check response model.

Uses ResponseBuilder.success pattern for standardized response formatting. Provides comprehensive consistency check results including detected inconsistencies, validation status, per-document analysis, cross-document issues, and actionable recommendations.

Fields: status: Check status (success/error) message: Response message data: Detailed consistency check results (ConsistencyCheckData) timestamp: Response generation timestamp

JSON Example: { “status”: “success”, “message”: “Lore consistency check completed”, “data”: { “overall_score”: 85.3, “consistency_level”: “good”, “document_results”: […], “total_issues”: 3, “critical_issues”: 0 }, “timestamp”: “2025-01-20T10:30:00Z” }

Used By: - POST /api/agents/lorekeeper/check-consistency - Writing Module consistency UI - Lore validation workflows

object
status
required
Status

Check status (success/error)

string
message
required
Message

Response message

string
data
required
ConsistencyCheckData

Detailed consistency check results

object
overallScore
required
Overallscore

Overall consistency score (0.0-100.0)

number
<= 100
consistencyLevel
required
Consistencylevel

Human-readable level: excellent, good, fair, poor, critical

string
documentResults
required
Documentresults

Per-document analysis results

Array<object>
DocumentConsistencyResult

Consistency check results for a single document.

Contains analysis results, issues found, and consistency score for one document in the batch check.

Fields: document_id: Document identifier (OPTIONAL) document_title: Document title for reporting (OPTIONAL) consistency_score: Overall score for this doc (REQUIRED, 0.0-100.0) issues: List of issues found in this doc (REQUIRED) warnings_count: Number of warnings (REQUIRED) errors_count: Number of errors (REQUIRED) entities_found: Entities detected in doc (OPTIONAL)

JSON Example: { “document_id”: “doc_123”, “document_title”: “Chapter 1: The Beginning”, “consistency_score”: 87.5, “issues”: [ { “issue_type”: “timeline_conflict”, “severity”: “medium”, “description”: “Event date conflicts with established timeline” } ], “warnings_count”: 2, “errors_count”: 0, “entities_found”: [“John Smith”, “New York”, “Excalibur Sword”] }

Used By: - LoreKeeper consistency check responses - Per-document analysis reporting - Writing Module consistency display

object
documentId
Any of:
string
documentTitle
Any of:
string
consistencyScore
required
Consistencyscore

Overall consistency score (0.0-100.0)

number
<= 100
issues
required
Issues

Issues found in this document

Array<object>
ConsistencyIssue

Individual lore consistency issue found during analysis.

Represents a specific inconsistency, conflict, or concern discovered during lore consistency checking with severity level and suggested fixes.

Fields: issue_type: Type of issue (REQUIRED) severity: Issue severity level (REQUIRED) description: Human-readable issue description (REQUIRED) location: Where the issue occurs (OPTIONAL) affected_entities: Entities involved in issue (OPTIONAL) suggestion: Suggested fix or resolution (OPTIONAL) confidence: AI confidence in detection (OPTIONAL, 0.0-1.0)

JSON Example: { “issue_type”: “character_contradiction”, “severity”: “high”, “description”: “Character age inconsistent between documents”, “location”: “document_1, paragraph 3”, “affected_entities”: [“John Smith”], “suggestion”: “Update age to match earlier reference (25 years)”, “confidence”: 0.92 }

Used By: - LoreKeeper consistency check responses - Consistency violation reporting - Fix suggestion systems

object
issueType
required
Issuetype

Type of issue (character_contradiction, timeline_conflict, lore_inconsistency, etc.)

string
severity
required
Severity

Issue severity: critical, high, medium, low, minor

string
description
required
Description

Human-readable description of the issue

string
location
Any of:
string
affectedEntities
Any of:
Array<string>
suggestion
Any of:
string
confidence
Any of:
number
<= 1
sourceHandler
Sourcehandler

DE handler model-id that produced this issue. Lorekeeper composes several sub-handlers (scene-contradictions, lore-ml-validation, entity-extract, prose-consistency); each sub-handler’s findings override this with the producer’s actual model-id.

string
default: divinity/lorekeeper-consistency
warningsCount
required
Warningscount

Number of warnings found

integer
errorsCount
required
Errorscount

Number of errors found

integer
entitiesFound
Any of:
Array<string>
crossDocumentIssues
Any of:
Array<object>
ConsistencyIssue

Individual lore consistency issue found during analysis.

Represents a specific inconsistency, conflict, or concern discovered during lore consistency checking with severity level and suggested fixes.

Fields: issue_type: Type of issue (REQUIRED) severity: Issue severity level (REQUIRED) description: Human-readable issue description (REQUIRED) location: Where the issue occurs (OPTIONAL) affected_entities: Entities involved in issue (OPTIONAL) suggestion: Suggested fix or resolution (OPTIONAL) confidence: AI confidence in detection (OPTIONAL, 0.0-1.0)

JSON Example: { “issue_type”: “character_contradiction”, “severity”: “high”, “description”: “Character age inconsistent between documents”, “location”: “document_1, paragraph 3”, “affected_entities”: [“John Smith”], “suggestion”: “Update age to match earlier reference (25 years)”, “confidence”: 0.92 }

Used By: - LoreKeeper consistency check responses - Consistency violation reporting - Fix suggestion systems

object
issueType
required
Issuetype

Type of issue (character_contradiction, timeline_conflict, lore_inconsistency, etc.)

string
severity
required
Severity

Issue severity: critical, high, medium, low, minor

string
description
required
Description

Human-readable description of the issue

string
location
Any of:
string
affectedEntities
Any of:
Array<string>
suggestion
Any of:
string
confidence
Any of:
number
<= 1
sourceHandler
Sourcehandler

DE handler model-id that produced this issue. Lorekeeper composes several sub-handlers (scene-contradictions, lore-ml-validation, entity-extract, prose-consistency); each sub-handler’s findings override this with the producer’s actual model-id.

string
default: divinity/lorekeeper-consistency
totalIssues
required
Totalissues

Total issues found

integer
criticalIssues
required
Criticalissues

Number of critical issues

integer
warningIssues
required
Warningissues

Number of warning-level issues

integer
suggestions
Any of:
Array<string>
analysisMetadata
Any of:

Arbitrary JSON-shaped data. Flattened from a recursive type alias for wiki rendering — the live API accepts any JSON-compatible value (string, number, bool, null, array, or nested object).

object
key
additional properties
any
analysisErrors
Any of:
Array<string>
timestamp
required
Timestamp

Response generation timestamp

string

Validation Error

HTTPValidationError
object
detail
Detail
Array<object>
ValidationError
object
loc
required
Location
Array
msg
required
Message
string
type
required
Error Type
string
input
Input
ctx
Context
object