middleware.namespaces.spec_whitelist

Namespace whitelist enforcement for dataset and vocabulary middleware.

Attributes

MatchDistance

Classes

WhitelistedTerm

A whitelisted term from a namespace.

WhitelistResult

Result of checking a term against the namespace whitelist.

WhitelistEntry

Internal vocabulary entry pairing a prefix with an rdflib namespace.

RestrictedNamespaceWhitelist

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.BaseModel

A 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].

namespace: str = None
vocabulary_type: Literal['closed', 'open'] = None
prefix: str = None
term: axiom.common.N3IRIRef = None
qname: str = None
class middleware.namespaces.spec_whitelist.WhitelistResult(/, **data: Any)

Bases: pydantic.BaseModel

Result 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].

allowed: bool = None
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 (DefinedNamespace subclasses) 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.

prefix: str
namespace: rdflib.Namespace | type[rdflib.namespace.DefinedNamespace]
property is_closed: bool

Return whether this entry uses a closed DefinedNamespace vocabulary.

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 through VocabularyConfiguration rather than assembling whitelist entries ad hoc.

entries: tuple[WhitelistEntry, Ellipsis]
find_term(uri: rdflib.URIRef) → WhitelistResult

Test uri against the whitelist and return nearest matches when rejected.

enumerate_prompt() → str | None

Return Research-Agent-facing guidance listing allowed vocabularies.

allows_namespace(namespace: rdflib.URIRef | rdflib.Namespace | str) → bool

Return whether any whitelist entry covers namespace.