middleware.namespaces.spec_whitelist ==================================== .. py:module:: middleware.namespaces.spec_whitelist .. autoapi-nested-parse:: Namespace whitelist enforcement for dataset and vocabulary middleware. Attributes ---------- .. autoapisummary:: middleware.namespaces.spec_whitelist.MatchDistance Classes ------- .. autoapisummary:: middleware.namespaces.spec_whitelist.WhitelistedTerm middleware.namespaces.spec_whitelist.WhitelistResult middleware.namespaces.spec_whitelist.WhitelistEntry middleware.namespaces.spec_whitelist.RestrictedNamespaceWhitelist Module Contents --------------- .. py:type:: MatchDistance :canonical: 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])] .. py:class:: WhitelistedTerm(/, **data: Any) Bases: :py:obj:`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. .. py:attribute:: model_config Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict]. .. py:attribute:: namespace :type: str :value: None .. py:attribute:: vocabulary_type :type: Literal['closed', 'open'] :value: None .. py:attribute:: prefix :type: str :value: None .. py:attribute:: term :type: rdflib_reasoning.axiom.common.N3IRIRef :value: None .. py:attribute:: qname :type: str :value: None .. py:class:: WhitelistResult(/, **data: Any) Bases: :py:obj:`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. .. py:attribute:: model_config Configuration for the model, should be a dictionary conforming to [`ConfigDict`][pydantic.config.ConfigDict]. .. py:attribute:: allowed :type: bool :value: None .. py:attribute:: term :type: WhitelistedTerm | None :value: None .. py:attribute:: nearest_matches :type: collections.abc.Sequence[tuple[WhitelistedTerm, MatchDistance]] :value: None .. py:class:: 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. .. py:attribute:: prefix :type: str .. py:attribute:: namespace :type: rdflib.Namespace | type[rdflib.namespace.DefinedNamespace] .. py:property:: is_closed :type: bool Return whether this entry uses a closed ``DefinedNamespace`` vocabulary. .. py:class:: 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. .. py:attribute:: entries :type: tuple[WhitelistEntry, Ellipsis] .. py:method:: find_term(uri: rdflib.URIRef) -> WhitelistResult Test ``uri`` against the whitelist and return nearest matches when rejected. .. py:method:: enumerate_prompt() -> str | None Return Research-Agent-facing guidance listing allowed vocabularies. .. py:method:: allows_namespace(namespace: rdflib.URIRef | rdflib.Namespace | str) -> bool Return whether any whitelist entry covers ``namespace``.