Bug Description
cognee.search(..., retriever_specific_config={"response_model": MyModel}) fails after retrieval succeeds. The retriever
returns a Pydantic MyModel instance, but SearchResultPayload.completion is typed Optional[Union[str, List[str], List[dict]]], which rejects a model instance → ValidationError when the payload is built at
cognee/modules/search/methods/get_retriever_output.py:80.
Two problems:
- The
response_model search path can't return a structured object — the payload type doesn't accept a BaseModel.
- When that
ValidationError is logged, cognee's structlog → rich exception renderer recurses in rich/pretty._traverse
and hangs indefinitely, so instead of a fast error the call appears to deadlock.
Steps to Reproduce
Minimal (no graph/LLM needed — it's pure result packaging):
from cognee.modules.search.models.SearchResultPayload import SearchResultPayload
from cognee.modules.search.types.SearchType import SearchType
from pydantic import BaseModel
class DealBrief(BaseModel):
deal_name: str = ""
health: str = ""
SearchResultPayload(completion=DealBrief(deal_name="Acme"), search_type=SearchType.GRAPH_COMPLETION)
End-to-end:
await cognee.search(
query_text="Brief for the Acme deal",
query_type=SearchType.GRAPH_COMPLETION,
datasets="my_dataset",
retriever_specific_config={"response_model": DealBrief},
)
Expected Behavior
search() with a response_model returns the populated model instance (schema-conforming structured output). The completion
retrievers already accept response_model via retriever_specific_config, and generate_completion returns a model
instance — only the result payload can't carry it.
Actual Behavior
pydantic ValidationError: N validation errors for SearchResultPayload at get_retriever_output.py:80:
completion.str: Input should be a valid string [input_type=DealBrief]
completion.list[str].0 / list[dict[any,any]].0: ...
Separately, logging that exception hangs indefinitely in rich/pretty._traverse (cognee/shared/logging_utils.py →
structlog → rich traceback), so the call never returns and looks like a deadlock.
Environment
Environment
- OS: macOS (Darwin 25.3.0, arm64)
- Python: 3.12.13
- Cognee: 1.1.2 (installed from
dev)
- LLM Provider: Baseten (gpt-oss-120b) + OpenAI embeddings
- Database: default local Kuzu/Ladybug graph + LanceDB
- Note: the failure is store-independent — it's in post-retrieval result packaging, so it reproduces on any backend.
Logs/Error Messages
Additional Context
Root cause: SearchResultPayload.completion (in cognee/modules/search/models/SearchResultPayload.py) is
Optional[Union[str, List[str], List[dict]]] — no BaseModel, and no serializer (whereas result_object has a
field_serializer for complex types).
Suggested fix: widen completion to accept a model (e.g. add BaseModel to the Union) and model_dump() it on output;
and harden the exception logger so rich traceback rendering can't hang on the error object.
Pre-submission Checklist
Bug Description
cognee.search(..., retriever_specific_config={"response_model": MyModel})fails after retrieval succeeds. The retrieverreturns a Pydantic
MyModelinstance, butSearchResultPayload.completionis typedOptional[Union[str, List[str], List[dict]]], which rejects a model instance →ValidationErrorwhen the payload is built atcognee/modules/search/methods/get_retriever_output.py:80.Two problems:
response_modelsearch path can't return a structured object — the payload type doesn't accept aBaseModel.ValidationErroris logged, cognee's structlog → rich exception renderer recurses inrich/pretty._traverseand hangs indefinitely, so instead of a fast error the call appears to deadlock.
Steps to Reproduce
Minimal (no graph/LLM needed — it's pure result packaging):
End-to-end:
Expected Behavior
search()with aresponse_modelreturns the populated model instance (schema-conforming structured output). The completionretrievers already accept
response_modelviaretriever_specific_config, andgenerate_completionreturns a modelinstance — only the result payload can't carry it.
Actual Behavior
pydantic ValidationError: N validation errors for SearchResultPayloadatget_retriever_output.py:80:Separately, logging that exception hangs indefinitely in
rich/pretty._traverse(cognee/shared/logging_utils.py→structlog → rich traceback), so the call never returns and looks like a deadlock.
Environment
Environment
dev)Logs/Error Messages
Additional Context
Root cause:
SearchResultPayload.completion(incognee/modules/search/models/SearchResultPayload.py) isOptional[Union[str, List[str], List[dict]]]— noBaseModel, and no serializer (whereasresult_objecthas afield_serializerfor complex types).Suggested fix: widen
completionto accept a model (e.g. addBaseModelto theUnion) andmodel_dump()it on output;and harden the exception logger so rich traceback rendering can't hang on the error object.
Pre-submission Checklist