The Semantic Layer, From ScratchChapter 13
Chapter 13

The Stardog toolbox

Which Stardog tool is for whom, which login each one needs, and how Voicebox turns a plain-English question into SPARQL.

Here's a puzzle. You paste the federated query from Chapter 9 into Studio, press Run, and there's Carolyn Inworth at the top with $502,529.42. You copy the same query into a five-line Python script, point it at the same database, and log in with the same email and password. The answer: 401 Unauthorized. What changed?

Section 13.2 answers that, and the answer explains how Stardog Cloud is put together. Then we tour the toolbox, including its star, Voicebox, which does for business users what Chapter 14's agent will do for you. Nothing gets built here. The one hands-on step is read-only: ask Voicebox a question and read the SPARQL it writes, which works only because your ontology and virtual graphs (Chapters 6 to 9) are in place.

13.1Terms in this chapter

TermWhat it isWhy it existsTiny example
Stardog Cloud portalThe website where people sign inManages endpoints, launches appscloud.stardog.com, email login
EndpointThe Stardog server itselfStores graphs, answers queries<your-endpoint>.stardog.cloud:5820
Native userA user account on the endpointPrograms need credentials the server knowsstardog_admin, role cloud
VoiceboxStardog's natural-language question boxQuestions without writing SPARQL"Top spenders in Wisconsin?" → SPARQL → answer
Grounded answerAn answer whose facts all came from a querySo an LLM can't make numbers upThe answer shows its SPARQL
Stored queryA named SPARQL query saved on the serverReuse, sharing, teaching Voiceboxsystem:QueryQ10546 in the kit
Knowledge kitA packaged semantic layer described by kit.yamlInstalls model, rules, data and queries at onceThe c360 training kit
MCP (Model Context Protocol)A standard plug between AI apps and toolsAny AI host can call any tool serverClaude Desktop calling voicebox_ask

13.2Two front doors: the portal and the endpoint

Stardog Cloud has two things with two addresses. The portal, cloud.stardog.com, is where you sign in with your email: a control panel that lists your endpoints, launches the web apps, and manages API keys. The endpoint, https://<your-endpoint>.stardog.cloud:5820, is the actual Stardog 12.1.4 server in us-west-2. It has its own HTTP API (POST /kit-c360/query runs SPARQL) and its own users, unrelated to portal accounts.

That's the answer to the puzzle. In Studio, the portal connects to the endpoint on your behalf. A Python script has no portal in the middle, so it must bring credentials the endpoint knows, which your email isn't. Hence this project's native Stardog user, stardog_admin, with the role cloud, plus hr since Chapter 12: with named-graph security on, cloud alone reads no graphs, and hr grants each graph by name. Every program in this book, including the Chapter 14 agent, signs in as stardog_admin (or as one of the narrower users from Chapter 12).

You browser email / SSO login Your program agent.py, pystardog, curl native user + password Cloud portal cloud.stardog.com Studio, Designer, Explorer, Voicebox, API keys Endpoint <your-endpoint>.stardog.cloud:5820 database kit-c360 its own users and roles stardog_admin (cloud + hr), hr_user, marketing_user apps connect on your behalf portal login does not work here
Figure 13.1: Two front doors. People sign in to the portal; programs talk to the endpoint as a native Stardog user.

13.3Studio, Designer and Explorer: one graph, three audiences

Studio is the engineer's IDE, the tool you've lived in since Chapter 2. What DBeaver is for SQL, Studio's Workspace is for SPARQL. It holds the query editor with its reasoning toggle (Chapter 10), Databases for loading data and setting properties (Chapter 6), the Models view, the Data area for data sources and virtual graphs (Chapters 7 to 9), and Security (Chapter 12).

Designer is for modelers. You draw classes as boxes and relationships as arrows, attach a table or CSV to each class, and publish; Designer writes the ontology into a named graph and creates the mappings. Its fingerprints are in the kit: in c360_extended_rules.ttl, each rule:content has a <tag:stardog:designer:rule:content> copy and a compressed designer:rule:data blob from Designer's rule editor. So why write everything by hand? Because when something breaks (a missing sql.schemas, the reserved word date, a float drifting by two cents), you need to know what Designer generates underneath: the same triples, just faster.

Explorer is for browsing: search for a customer, land on her page, click her address or an order, and keep walking. It's Chapter 2's "follow the arrows" as a web page; the kit's kit.yaml gives it a starting point, initialSearch: "`urn:stardog:demos:c360:customer:230`". Its search depends on the full-text index (search.enabled), and virtual-graph data isn't stored in Stardog, so it may not be indexed. If Explorer can't find "Carolyn Inworth" but your Chapter 9 query can, that's probably why; check the docs for your version before promising Explorer on a purely virtual setup.

13.4Voicebox: English in, SPARQL out

A business user types "Who are the top spenders in Wisconsin?" and Voicebox writes SPARQL, runs it, answers in a sentence, and shows the query. Underneath is a large language model (LLM), but what makes it work is your semantic layer. Press Play to watch.

Who are the top spenders in Wisconsin? "spenders" → ontology labels "price" = :purchasePrice "quantity" = :quantity "purchased by" = :purchasedBy Order → Customer (rdfs:label, so:domainIncludes) "Wisconsin" → search a value, not a class found as a "state" :state on :Address, reached by :address (full-text search index) "top" → examples similar stored queries show the pattern: SUM, GROUP BY, ORDER BY DESC, LIMIT (system:voiceboxQuestion) Generated SPARQL (illustrative) SELECT ?name (SUM(?price * ?qty) AS ?spend) WHERE { ?c a :Customer ; :name ?name ; :address ?a . ?a :state "Wisconsin" . ?o :purchasedBy ?c ; :purchasePrice ?price ; :quantity ?qty . } GROUP BY ?name ORDER BY DESC(?spend) LIMIT 10 → Stardog runs it over the virtual graphs → "Carolyn Inworth, $502,529.42 …"

Figure 13.2: How Voicebox turns words into a query. The colors match each word to the part of the query it produced.

How does Voicebox know how to query this ontology?

Not from its training data. It reads four things you built:

  1. The ontology (the T-Box). Per the Voicebox developer guide, it uses rdfs:label for names, rdfs:comment for descriptions, rdfs:subClassOf for the hierarchy, and so:domainIncludes/so:rangeIncludes for which properties connect which classes. The guide recommends the schema.org pair over rdfs:domain/rdfs:range, the practical reason the c360 kit uses them (Chapter 6). "Spenders" matches no class, but it lands near the labels "price", "quantity" and "purchased by".
  2. The search index. "Wisconsin" is a value, not part of the ontology. Voicebox finds values with full-text search, which is why enabling Voicebox also switches on search.enabled.
  3. Example questions. Shared stored queries tagged with system:voiceboxQuestion are shown to the LLM as worked examples. This is few-shot prompting: teaching by showing a few solved problems.
  4. The engine. Stardog runs the finished query the normal way, virtual graphs and pushdown included (Chapter 9).

Here is one of the kit's 317 stored queries, trimmed; each pairs English with SPARQL:

system:QueryQ10546 a system:StoredQuery , system:SharedQuery ;
  system:queryDatabase "kit-c360" ;
  system:voiceboxQuestion "Which rewards account customers bought at least $10K in a single order?" ;
  system:queryString """SELECT DISTINCT ?customer0 WHERE {
  ?order0 a ecomm:Order .
  ?order0 ecomm:purchasePrice ?dat_0 .
  ?order0 ecomm:purchasedBy ?customer0 .
  ?customer0 ecomm:hasRewards ?rewardsAccount0 .
  FILTER ("10000.00"^^xsd:decimal <= ?dat_0)
}""".

This one example teaches that the arrow runs from order to customer (?order0 ecomm:purchasedBy ?customer0), that money is compared as xsd:decimal, and that the query returns IRIs rather than names. The docs recommend exactly that (Voicebox looks up the labels before showing results), and suggest starting with five to ten examples that together cover the whole model.

Three notes for our database. First, Voicebox has to be on: the database option voicebox.enabled (the kit's kit.yaml sets it to true) can only be enabled if the server's license allows Voicebox. Second, a Voicebox app lets you choose its data graph, schema and reasoning setting. Our facts live only in virtual graphs, so if Voicebox finds nothing where your Chapter 9 query finds Carolyn, check that setting first. Third, the kit's examples were written for its CSV data, and a couple use properties our mappings don't produce (ecomm:race). The best examples are ones you write, such as your Chapter 9 query saved as "Who are the top spenders?".

13.5Stored queries and knowledge kits

A stored query is SPARQL saved on the server under a name, with metadata. The kit ships its 317 as Turtle, since Stardog keeps stored queries as triples in its system catalog. The types: system:StoredQuery (saved), system:SharedQuery (visible to others; Voicebox learns only from shared ones), and system:ReasoningQuery (run with reasoning on). In Studio you save one from the editor. Chapter 14's five competency questions, with their verified queries, are ideal candidates: a regression suite, Voicebox examples, and reference answers for the agent.

A knowledge kit is a semantic layer in a box. Its manifest, kit.yaml, reads like this book's summary:

kit.yaml sectionWhat the c360 kit saysWhere you did it
optionssearch.enabled, graph.aliases, voicebox.enabled all trueThe database the kit created
namespacesecomm: "tag:stardog:api:ecomm:"Chapter 3
data (models)schema.ttl → the model graph; extended model and rules → urn:stardog:c360_extended_rules:1.0:modelChapters 5, 6, 10
data (CSVs)Eight CSVs with .sms mappings, copied into urn:stardog:training-c360:1.0:dataReplaced by virtual graphs (Chapters 7 to 9)
schemasc360_schema, c360_extended_rulesreasoning.schemas (Chapters 6, 10)
querieskit-queries.ttlStored queries, above

The fourth row is the interesting one. The kit materializes its data (Chapter 7's ETL-style option). You kept its model, rules and IRI patterns and swapped that one section for live virtual graphs. Because your mappings mint the same IRIs (urn:stardog:demos:c360:customer:{cid} and friends), the kit's rules and stored queries still fit: the Chapter 9 IRI trick pays off a second time.

13.6The Stardog Cloud MCP server

MCP (Model Context Protocol) is an open standard for connecting AI applications to tools. An MCP server advertises tools, each with a name, a description and a JSON schema for its arguments. An MCP host (Claude Desktop, Claude Code, Cursor, or your own agent) discovers them and lets its model call them. MCP is to AI tools roughly what JDBC is to databases: one standard plug.

Stardog publishes an open-source server on GitHub, stardog-union/stardog-cloud-mcp. Its README lists exactly three tools, all built on the Voicebox APIs:

ToolWhat it does
voicebox_settingsReturns your Voicebox application's settings: database, model and configuration.
voicebox_askAsks a natural-language question and returns Voicebox's full answer, with its reasoning chain, the SPARQL it ran, and provenance.
voicebox_generate_queryTurns a question into SPARQL without running it, so your code can check the query first.
MCP host Claude Desktop, Cursor, your agent stardog-cloud-mcp voicebox_settings voicebox_ask voicebox_generate_query Voicebox API cloud.stardog.com API key (app) Endpoint kit-c360 → Aurora, Redshift local: started by the host via uv · remote (beta): HTTP on port 7001, token in x-sdc-api-key
Figure 13.3: The MCP server is a thin adapter. It doesn't run your SPARQL; it passes questions to Voicebox, which writes and runs the SPARQL.

To run it you need a Voicebox API token: in the portal's profile menu, choose Manage API Keys, create an application and generate a secret. That's a third kind of credential, neither your portal login nor stardog_admin. Not on the Free tier. The Voicebox developer guide says "Manage API Keys" only appears "if your organization has been given Voicebox API access", and on a Free account the profile menu has no such entry (checked: it lists Update Profile, Update Cookie Consent, Logout, My Workspace and Delete Account; a Stardog Community thread reports the same). No key means no MCP server, so on the Free tier read this part along. Nothing later depends on it: the Chapter 14 agent talks to Stardog directly with a username and password (stardog_admin, hr_user or marketing_user). Locally, the server runs on Python 3.12 or 3.13 with uv, started by the host (uv run stardog-cloud-mcp --token … --client_id …). The remote mode is beta: a Docker container serving HTTP on port 7001, with the token in an x-sdc-api-key header.

13.7Which tool, for whom, with which login

ToolForSigns in withBest at
StudioEngineersPortal loginSPARQL, loading, virtual graphs, security
DesignerModelersPortal loginDrawing ontologies and mappings
ExplorerAnalystsPortal loginBrowsing entities and links
VoiceboxBusiness usersPortal loginPlain-English questions, with the query shown
HTTP API / pystardogPrograms, the Chapter 14 agentNative userRunning exact SPARQL
MCP serverAI hosts and agentsVoicebox API tokenVoicebox as a tool

Check yourself

Back to the opening puzzle: why does the script get a 401 when Studio works?

Studio goes through the portal, which connects to the endpoint for you. The script talks to the endpoint directly, and the endpoint doesn't know portal accounts. Programs need a native Stardog user: stardog_admin or a narrower Chapter 12 user.

Name the four things Voicebox relies on to answer a question.

The ontology's labels, comments and domain/range hints; the full-text search index (for values like "Wisconsin"); shared stored queries with system:voiceboxQuestion examples; and the Stardog engine, which runs the query through the virtual graphs.

What does "grounded" mean, and what can still go wrong?

Every fact in the answer came from a query against your graph, and the query is shown. The query can still be wrong (a missing * quantity, the wrong graph), so you keep reference answers.

The kit loads CSVs into a data graph. Why do its rules and queries still work over your virtual graphs?

Your mappings mint the same IRIs and use the same ontology terms, so rules and queries match virtual triples exactly as they would copied ones.

Can the Stardog Cloud MCP server run a specific SPARQL query you've verified?

No. All three of its tools go through Voicebox. For exact queries use the HTTP API or pystardog, which is Path A in Chapter 14.

Chapter recap