middleware.namespaces.spec_whitelist¶
Namespace whitelist enforcement for dataset and vocabulary middleware.
Attributes¶
Classes¶
A whitelisted term from a namespace. |
|
Result of checking a term against the namespace whitelist. |
|
Internal vocabulary entry pairing a prefix with an rdflib namespace. |
|
A fixed whitelist of namespaces allowed in the knowledge base. |
Module Contents¶
- type middleware.namespaces.spec_whitelist.MatchDistance = Annotated[int, Field(ge=0, description='Levenshtein distance between the rejected qualified name and the suggested qualified name, used for ranking (lower is better). For example, the distance between rdfs:type and rdf:type is 1; between rdfs:Classs and owl:Class is 5.', examples=[0, 1, 3])]¶
- class middleware.namespaces.spec_whitelist.WhitelistedTerm(/, **data: Any)¶
Bases:
pydantic.BaseModelA whitelisted term from a namespace.
Appears in tool error responses when a term is rejected by the namespace whitelist, identifying valid alternatives the agent may use instead.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- vocabulary_type: Literal['closed', 'open'] = None¶
- term: axiom.common.N3IRIRef = None¶
- class middleware.namespaces.spec_whitelist.WhitelistResult(/, **data: Any)¶
Bases:
pydantic.BaseModelResult of checking a term against the namespace whitelist.
Returned as structured JSON in tool error responses so the agent can inspect whether the term was allowed, retrieve metadata about the matched vocabulary entry, and review nearest-match suggestions.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- term: WhitelistedTerm | None = None¶
- nearest_matches: collections.abc.Sequence[tuple[WhitelistedTerm, MatchDistance]] = None¶
- class middleware.namespaces.spec_whitelist.WhitelistEntry¶
Internal vocabulary entry pairing a prefix with an rdflib namespace.
Closed vocabularies (
DefinedNamespacesubclasses) support term-level membership testing; open vocabularies (Namespace) support prefix-only matching. This dataclass is developer-facing and is never serialized to the agent boundary.- namespace: rdflib.Namespace | type[rdflib.namespace.DefinedNamespace]¶
- class middleware.namespaces.spec_whitelist.RestrictedNamespaceWhitelist(entries: collections.abc.Iterable[WhitelistEntry])¶
A fixed whitelist of namespaces allowed in the knowledge base.
This is internal runtime machinery used by
VocabularyContext. Callers SHOULD construct vocabulary policy throughVocabularyConfigurationrather than assembling whitelist entries ad hoc.- entries: tuple[WhitelistEntry, Ellipsis]¶
- find_term(uri: rdflib.URIRef) WhitelistResult¶
Test
uriagainst the whitelist and return nearest matches when rejected.
- allows_namespace(namespace: rdflib.URIRef | rdflib.Namespace | str) bool¶
Return whether any whitelist entry covers
namespace.