Skip to main content

Semantic Build

Semantic build enriches raw tool schemas with deterministic metadata that search and target selection can use.

Run semantic build during OpenAPI collection builds so large specs do not remain as anonymous unknown actions or unassigned resources.

Generated Metadata

FieldMeaning
canonical_actionsearch, read, create, update, delete, action, or unknown
primary_resourceThe main resource the operation is about
path_moduleStable module or route grouping from the path
operation_groupHigher-level operation grouping
result_shapesingle, list, count, mutation, or unknown
semantic_confidenceDeterministic confidence signal
semantic_evidenceSources that explain the metadata

Priority Rules

The engine prefers existing curated metadata first. If metadata is absent, it uses operation id, summary, description, HTTP method, path segments, tags, schema references, and identifier fields.

Product-specific dictionaries should be passed as options. They should not be hard-coded into the library.

Minimal Example

from graph_tool_call.graphify.semantics import annotate_openapi_tool_semantics

tools = annotate_openapi_tool_semantics(
tools,
options={
"resource_aliases": {"member": ["customer", "user"]},
"action_aliases": {"search": ["find", "lookup"]},
"module_aliases": {"orders": ["claim", "refund"]},
},
overwrite=False,
)

overwrite=False preserves operator-curated metadata. Use overwrite only when you intentionally want to rebuild semantic fields from source.

Artifact Summary

Collection artifacts should expose semantic coverage:

{
"semantic_summary": {
"canonical_action_known_rate": 0.96,
"primary_resource_assigned_rate": 0.82,
"path_module_assigned_rate": 0.99,
"result_shape_known_rate": 0.74,
"unknown_samples": ["legacyAction", "executeProc"]
}
}

Low rates are not cosmetic. They directly affect search ranking, target selection, and graph visualization.

Quality Checks

Track these rates after a build:

  • action known rate
  • resource assigned rate
  • module assigned rate
  • result shape known rate
  • unknown samples

Failure Modes

SymptomLikely CauseFix
many unknown actionsweak operation ids and summariespass action aliases or curate metadata
many unassigned resourcesbroad tags or generic path namespass resource aliases or inspect path modules
one module contains most toolsmodule derivation too coarseadjust module aliasing or source grouping
detail queries choose list toolsresult_shape missing or wrongimprove schema and summary hints