You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These parameters are part of the `EntityAndRelationExtractor` component.
@@ -138,6 +138,7 @@ They are also accessible via the `SimpleKGPipeline` interface.
138
138
# ...
139
139
prompt_template="",
140
140
lexical_graph_config=my_config,
141
+
enforce_schema=SchemaEnforcementMode.Strict
141
142
on_error="RAISE",
142
143
# ...
143
144
)
@@ -829,6 +830,38 @@ It can be used in this way:
829
830
830
831
The LLM to use can be customized, the only constraint is that it obeys the :ref:`LLMInterface <llminterface>`.
831
832
833
+
Schema Enforcement Behaviour
834
+
---------------
835
+
By default, even if a schema is provided to guide the LLM in the entity and relation extraction, the LLM response is not validated against that schema.
836
+
This behaviour can be changed by using the `enforce_schema` flag in the `LLMEntityRelationExtractor` constructor:
837
+
838
+
.. code:: python
839
+
840
+
from neo4j_graphrag.experimental.components.entity_relation_extractor import LLMEntityRelationExtractor
841
+
from neo4j_graphrag.experimental.components.types import SchemaEnforcementMode
842
+
843
+
extractor = LLMEntityRelationExtractor(
844
+
# ...
845
+
enforce_schema=SchemaEnforcementMode.STRICT,
846
+
)
847
+
schema = SchemaConfig(
848
+
entities={"Label": {"name": str}},
849
+
relations={"REL_TYPE": {}},
850
+
potential_schema=[("Label", "REL_TYPE", "Label")]
851
+
)
852
+
853
+
#....
854
+
result =await extractor.run(
855
+
#...
856
+
schema=schema
857
+
)
858
+
859
+
In this scenario, any extracted node/relation/property that is not part of the provided schema will be pruned.
860
+
Any relation whose start node or end node does not conform to the provided tuple in `potential_schema` will be pruned.
861
+
If a node is left with no properties, it will be also pruned.
862
+
863
+
Note that if the schema enforcement mode is on but the schema is not provided, no schema enforcement will be applied.
0 commit comments