diff --git a/src/neo4j_graphrag/experimental/components/entity_relation_extractor.py b/src/neo4j_graphrag/experimental/components/entity_relation_extractor.py index f21a22fed..112d8b2c6 100644 --- a/src/neo4j_graphrag/experimental/components/entity_relation_extractor.py +++ b/src/neo4j_graphrag/experimental/components/entity_relation_extractor.py @@ -404,7 +404,12 @@ def _enforce_nodes( if not schema_entity: continue allowed_props = schema_entity.get("properties", []) - filtered_props = self._enforce_properties(node.properties, allowed_props) + if allowed_props: + filtered_props = self._enforce_properties( + node.properties, allowed_props + ) + else: + filtered_props = node.properties if filtered_props: valid_nodes.append( Neo4jNode( @@ -469,7 +474,10 @@ def _enforce_relationships( continue allowed_props = schema_relation.get("properties", []) - filtered_props = self._enforce_properties(rel.properties, allowed_props) + if allowed_props: + filtered_props = self._enforce_properties(rel.properties, allowed_props) + else: + filtered_props = rel.properties valid_rels.append( Neo4jRelationship( diff --git a/tests/unit/experimental/components/test_entity_relation_extractor.py b/tests/unit/experimental/components/test_entity_relation_extractor.py index 21fe8807d..cebc3d31e 100644 --- a/tests/unit/experimental/components/test_entity_relation_extractor.py +++ b/tests/unit/experimental/components/test_entity_relation_extractor.py @@ -374,7 +374,7 @@ async def test_extractor_schema_enforcement_valid_nodes_with_empty_props() -> No result: Neo4jGraph = await extractor.run(chunks, schema=schema) - assert len(result.nodes) == 0 + assert len(result.nodes) == 1 @pytest.mark.asyncio