?s
sqlib SPARQL rules demo
W3C SPARQL-RL

sqlib SPARQL-RL demo

This site runs a read-only sqlib instance with three libraries. The first holds the 203 entries of the W3C SPARQL-RL test suite as sqlib tests. The second is a course in SPARQL rules, taken in Claude or ChatGPT through sqlib's tutorial MCP App. Each lesson lists the suite entries that test the behaviour it teaches. The third holds rules using aggregates, an extension sqlib implements from a proposal the specification does not include.

203 / 203 all pass
W3C SPARQL-RL suite entries passed by sqlib's test runner at the revision below. snapshot 2026-10-20 · sqlib 13d452b9b8ec
Library 1

W3C SPARQL-RL test suite

Each of the 203 syntax, well-formedness, stratification and evaluation entries is stored as a rule set and a test. Running an evaluation entry shows the inference graph it produces.

Library 2

SPARQL rules course

Ten lessons, from a first rule to stratification and the ground graph. Each lesson is a tag, each worked example a rule set, and each exercise a test.

Library 3

Aggregates (extension)

Rule sets using GROUP, the aggregation element proposed in w3c/data-shapes#1347. Each is tagged with the behaviour it shows, and most have a test. How aggregates work.

Your data

Your own SPARQL endpoint

An endpoint you register is stored in your browser's localStorage. Queries against it are sent from the browser tab, so the query text and results do not pass through the sqlib API. The endpoint must send CORS headers for the browser to read its responses.

Conformance snapshot

Report generated on 2026-10-20 and stored with the site. It is not re-run on page load.
CategoryChecksPassed
syntax document 139 / 139
wellformed document 8 / 8
stratification document 10 / 10
eval rules + data 35 / 35
eval2 rules + data 6 / 6
examples rules + data 5 / 5
Total203 / 203
Implementation
sqlib 13d452b9b8ec
Suite
w3c/data-shapes 9c863967, copied unedited into sqlib-demos
Harness
sqlib's library harness: each entry is seeded as a rule set and a test and run by the standard test runner, as in this demo
Assertor
David Habgood, from an automated build

The report is produced when the site is built and does not change afterwards. To run an entry again, open it in the library and press Run.

SPARQL rules tutorial (MCP App)

sqlib's MCP server publishes Views: HTML documents that an MCP Apps-capable chat client, such as Claude or ChatGPT, renders in a sandboxed frame inside the conversation. The app.tutorial.open tool opens the course in a View with each lesson's objectives, worked examples and exercises, edited in a CodeMirror editor with SRL syntax support.

Lesson 1 of the SPARQL rules tutorial rendered inside a chat client
Lesson 1, “Your first rule”, rendered by the tutorial View in a chat client.

Analysis in the editor

While you edit, the View reports whether the rule set parses, is well-formed and stratifies, which are the three checks the W3C suite makes of a document. Each rule's stratum is shown beside it.

Exercise checking

An answer that fails analysis is rejected before it runs. Otherwise it runs over the lesson's data graph, and the result is compared with the expected inference graph. Missing and unexpected triples are listed.

Hints from the chat model

The View reports the open lesson and each run's result to the chat model. Ask for a hint adds your current attempt to the conversation. Progress is not stored and is lost when the View closes.

SRL aggregates (extension)

GROUP is the aggregation element proposed for SPARQL-RL in w3c/data-shapes#1344, with the grammar of w3c/data-shapes#1347. Where that pull request leaves the meaning open, sqlib follows the behaviour clarified in later discussion in w3c/data-shapes#840. sqlib accepts it only when the FEATURE_RULE_AGGREGATES flag is on, which this site sets.

RULE { ?x :numChildren ?n }
WHERE {
  ?x a :Person
  GROUP BY ?x { ?y :childOf ?x } [ ?n := COUNT(*) ]
}
Over the library's Families graph, this rule gives 3 for each of the two parents and 0 for the person with no children.

How a GROUP joins the rest of the rule

  • The pattern's matches are grouped by the BY variables, the only variables it shares with the rest of the rule. A BY variable may be bound before the GROUP or supplied by the pattern. With no BY, every match is one group.
  • Every row that reaches the GROUP is kept, with every variable bound in it, and gains the BY variables and the results. A second GROUP keeps the first one's result.
  • The pattern's other variables belong to the GROUP, as a variable a subquery does not project belongs to the subquery: one of the same name before or after it is a different variable.

What a GROUP computes

  • The functions are COUNT(*), COUNT(DISTINCT ?v), SUM, MIN and MAX, and one GROUP can assign several results.
  • The functions run over the solutions of the pattern, as in SPARQL, so two children aged 10 both count towards SUM.
  • The number of outer rows does not change a result: a person with two names and three children gets a count of 3 on both rows.
  • For a key bound before the GROUP, an empty group gives 0 for COUNT and SUM, and MIN and MAX have no value, so the row is dropped. A key only the pattern supplies has no value for an empty group, so there is no row.
  • An error in any result drops the row, as an error in SET does.

What the extension rejects

  • A variable used both inside the pattern and elsewhere in the rule without being listed after BY is not well-formed. Correlation therefore has to be stated, and renaming a variable cannot silently change what is counted.
  • AVG, SAMPLE and GROUP_CONCAT, an expression as an argument, and DISTINCT outside COUNT are rejected, as #1347's grammar does not include them.
  • The pattern cannot contain NOT or another GROUP, and a GROUP cannot appear inside NOT.
  • A rule whose GROUP reads its own output does not stratify. A rule with a GROUP runs once, in a stratum above every rule that derives what it counts, so the counted triples are complete before it fires.
  • There is no HAVING; a FILTER on the result, after the GROUP, filters the same rows.

How a GROUP is compiled

  • A rule with a GROUP compiles to a SPARQL 1.2 program, like every SRL rule. The GROUP becomes a subquery grouped by the BY variables and joined to the rest of the rule, OPTIONAL when every key is bound before it, written only with forms SPARQL 1.1 already had.
  • The pattern's own variables are renamed, so the subquery shares only the keys with the rest of the rule.
  • A hidden count in the subquery separates an empty group from an aggregate that failed.
Aggregation: GROUP, in the SRL reference The aggregates library

Connect Claude or ChatGPT

Add the server URL below as a custom connector in your chat client. The chat uses your existing Claude or ChatGPT plan, so this site needs no API key or account. The server has no authentication and publishes only read-only tools.

Server URL …
Add to Claude Opens the Add custom connector dialog on claude.ai with the server URL filled in. Press Add to finish.
    Then, in a new chat, ask Open the sqlib SPARQL rules tutorial at lesson 1. These steps were checked on 2026-09-24; Claude and ChatGPT change these menus from time to time. On Claude Team and Enterprise plans, an organisation owner must add the connector first.

    Architecture

    The site runs an unmodified sqlib release. The sqlib-demos repository adds the suite files, the course, and configuration that sets the API to read-only.

    Your browser
    sqlib web app Static files on S3, served by CloudFront. This page is the site's front page; the application is at /sqlib.
    Browser backends SPARQL endpoints you register, stored in localStorage and queried from the tab.
    REST
    ECS Fargate
    sqlib API read-only
    /api
    libraries, tests, run, format
    /mcp
    tools + ui://sqlib/tutorial
    Library store, seeded at build: W3C suite (203) + SRL course (10 lessons)
    MCP
    Chat client
    Claude or ChatGPT A custom connector on your plan. The model calls sqlib's MCP tools.
    Tutorial View Runs in a sandboxed iframe with no network access. It reaches sqlib only through calls relayed by the chat client.

    Built from sqlib-demos: the Docker image pins a sqlib revision and seeds the libraries from committed files. Before deployment, scripts/check-readonly-contract.sh checks that the API refuses writes.

    Part of sqlib

    sqlib stores parameterised SPARQL queries, rule sets, tests and ETL jobs as versioned RDF, and provides a web application, a REST API and an MCP server. This demo covers its SPARQL-RL implementation.

    sqlib on GitHub Demo source SPARQL-RL specification W3C test suite MCP App guide