Skip to content

ModelSchema

relationalai.semantics.inspect
ModelSchema(
name: str,
concepts: tuple[ConceptInfo, ...],
enums: tuple[EnumInfo, ...],
tables: tuple[TableInfo, ...],
bare_relationships: tuple[RelationshipInfo, ...],
defines: tuple[RuleInfo, ...] = (),
requires: tuple[RuleInfo, ...] = (),
)

Complete schema of a Model.

One object, full picture. Access concepts by name with ms["Person"] or "Person" in ms. Serialize with ms.to_dict() (JSON-safe) or str(ms) (human-readable summary grouped by section).

Notes

Within each ConceptInfo, properties and relationships preserve effective lookup order: members declared on the concept appear before inherited members, and subtype redeclarations shadow inherited same-name members.

to_dict() uses dataclasses.asdict which preserves tuples (not lists). json.dumps(ms.to_dict()) works correctly — JSON arrays for both.

Attributes

.name

ModelSchema.name: str

Model name.

.concepts

ModelSchema.concepts: tuple[ConceptInfo, ...]

All non-enum concepts, in model declaration order. Enum concepts appear in enums instead.

.enums

ModelSchema.enums: tuple[EnumInfo, ...]

Enumeration types with their member values, in declaration order.

.tables

ModelSchema.tables: tuple[TableInfo, ...]

External table references and temporary tables created by model.Table() and model.data(), in overall creation order.

.bare_relationships

ModelSchema.bare_relationships: tuple[RelationshipInfo, ...]

Relationships (including properties) not owned by any concept. These come from model.relationships and are shown as “Standalone Declarations” in str() output. Use is_property to distinguish properties from multi-valued relationships. Order matches model.relationships.

Methods

.get()

ModelSchema.get(name: str, default: ConceptInfo | None = None) -> ConceptInfo | None

Look up a concept by name.

Parameters:

  • name

    (str) - Concept name to look up.
  • default

    (ConceptInfo | None, default: None) - Value to return if the concept is not present.

Returns:

  • ConceptInfo | None - The matching concept, or default if no concept with that name exists.

.to_dict()

ModelSchema.to_dict() -> dict[str, Any]

Return a JSON-safe dictionary representation.

Returns:

  • dict[str, Any] - Nested dictionary mirroring the dataclass structure. Collections remain as tuples; json.dumps handles them as arrays. A json.loads round-trip converts tuples to lists.

Returned By

 semantics > inspect
└──  schema