Skip to main content

agrag.common.data_models.graph_schema.GraphSchema

Bases: BaseModel

A versioned contract of entity and relation types.

Every extraction call is validated against a GraphSchema. There is no schema-free extraction path. Round-trip with model_dump(mode="json") and model_validate(). A schema declaring an entity property name that the vector payload reserves fails that validation, so a payload written before the check existed must be migrated before it loads again. See EntityType.properties.

Attributes:

  • name (str) – A short, unique name for this schema.
  • version (str) – The schema version. Bump when types or patterns change.
  • entities (list[EntityType]) – The entity types this schema recognizes.
  • relations (list[RelationType]) – The relation types this schema recognizes.

Functions:

entities​

entities: list[EntityType]

name​

name: str

relations​

relations: list[RelationType]

to_compact_summary​

to_compact_summary() -> str

Serialize only entity labels and relation patterns for a prompt.

Descriptions, properties, and subtypes are omitted, so this is the shape to inject where prompt space is tight. to_prompt_description carries the same labels with their full detail.

Returns:

  • str – A plain-text summary of entity labels and valid relation
  • str – patterns.

to_prompt_description​

to_prompt_description() -> str

Serialize this schema in full for an LLM prompt.

Every entity type's label, description, declared properties, and subtypes are listed, followed by every relation type's label, description, and valid (source, target) patterns. Use to_compact_summary instead when prompt space is tight.

Returns:

  • str – A plain-text schema description, one fact per line.

version​

version: str