fix(graphiti_core): default list fields in response models to prevent ValidationError on empty LLM output#1416
Open
kromanow94 wants to merge 2 commits intogetzep:mainfrom
Open
Conversation
…r on empty LLM output
When Anthropic or Gemini models return empty tool input `{}` (e.g. when
no entities or edges are found), Pydantic validation fails because list
fields are defined as required with no default. This changes them to
default to empty lists, which is the correct semantic for "nothing found"
and is already handled by downstream code.
Affected models: ExtractedEntities, SummarizedEntities, ExtractedEdges,
EdgeDuplicate, NodeResolutions.
Covers all 5 affected models with both empty input (the bug scenario) and populated input (normal operation) to prevent regressions.
Author
|
I have read the CLA Document and I hereby sign the CLA |
Member
|
All contributors have signed the CLA ✍️ ✅ |
danielchalef
added a commit
that referenced
this pull request
Apr 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Several Pydantic response models crash with
ValidationErrorwhen the LLM returns an empty dict{}as structured output. This happens because list fields are defined as required (Field(...)) with no default value.LLM providers that don't enforce
requiredfields server-side (Anthropic, Gemini) can return{}when there's nothing to extract. This causesresponse_model(**{})to fail, and retries don't help since the model makes the same decision.This PR changes the affected list fields from
Field(...)toField(default_factory=list)so that empty LLM output is treated as "nothing found" instead of crashing.Type of Change
Bug Details
Error logs:
After 2 retries, the error propagates and the episode fails to process.
Call path (Anthropic):
Affected clients:
anthropic_client.py)response_model(**response)at line 403gemini_client.py)response_model.model_validate(...)at line 329openai_base_client.py)OpenAI's structured output feature enforces the schema via constrained decoding, guaranteeing valid output. Anthropic and Gemini do not enforce
requiredfields server-side.Changes
6 fields across 4 files, all
Field(...)->Field(default_factory=list):prompts/extract_nodes.pyExtractedEntitiesextracted_entitiesprompts/extract_nodes.pySummarizedEntitiessummariesprompts/extract_edges.pyExtractedEdgesedgesprompts/dedupe_edges.pyEdgeDuplicateduplicate_factsprompts/dedupe_edges.pyEdgeDuplicatecontradicted_factsprompts/dedupe_nodes.pyNodeResolutionsentity_resolutionsBefore / After:
Why this is safe:
{"extracted_entities": [...]}.Testing
Added
tests/prompts/test_response_models.pywith 10 tests covering all 5 affected models:Model(**{})produces valid instances with empty lists (the regression scenario)Breaking Changes
Checklist
make lintpasses)Environment