Turn text into a knowledge graph. You say what to look for; every fact keeps the words it came from.
SchemaCast reads short texts (news, messages, notes, tickets) and writes what they state as a graph: the entities, how they relate, and what is said about them. A schema of a few lines says what to look for. Each text is one model call, checked against that schema.
Status: alpha. The API may change between minor releases.
1. Install
pip install schemacast2. Say what to look for, in a few lines of YAML (schema.yaml):
name: deals
types:
Company: {key: name, fields: {name: str, sector: str, city: str}}
Person: {key: name, fields: {name: str}}
relations:
- Person CEO_OF Company
- Company ACQUIRED Company3. Cast your texts, one per line (notes.jsonl):
{"source_id": "note-1", "text": "Brightline, a payments company in Austin, acquired Oakfield for $40 million."}
{"source_id": "note-4", "text": "Contrary to earlier reports, Raj Patel is not the CEO of Westpeak."}export SCHEMACAST_LLM_API_KEY=sk-... # or any OpenAI-compatible endpoint, a local Ollama included
schemacast cast --schema schema.yaml --episodes notes.jsonl --out out/Out comes the graph, and every fact with the words it was read from (as the example's demo prints it):
note-1 Company 'Brightline, a payments company in Austin'
note-1 name 'Brightline'
note-1 sector 'payments company'
note-1 city 'Austin'
note-1 Company 'Oakfield'
note-1 name 'Oakfield'
note-1 ACQUIRED 'Brightline, a payments company in Austin, acquired Oakfield for $40 million.'
note-1 price '$40 million'
note-4 Person 'Raj Patel'
note-4 Company 'Westpeak'
note-4 CEO_OF 'Raj Patel is not the CEO of Westpeak' denied
$40 million is stored as price: 40000000.0, checked as a number. The denial is kept with its
quote and never written to the graph.
No key yet? From a clone, uv run python examples/hello/demo.py runs this example on replies
recorded once, for free. Its ten lines are also all it takes from Python.
- Checked facts. Types, relations and values are checked against the schema; a reply that fails is corrected at most twice, then set aside with its reason, never guessed.
- One entity per key. "Brightline" in three notes is one company. A mention without its key waits until a lookup can identify it, instead of creating a duplicate.
- Quotes and nuance. Every fact keeps its quote and character span, and what the text says about it: when it holds, whether it is only planned or hedged, and whether the text denies it. A denial is kept, never written to the graph.
- Free reruns. Replies are cached;
--replaymakes no request and gives the same graph, byte for byte. - Your database.
--db conn.yamlwrites to any database GraFlo supports, Neo4j and ArangoDB among them. Writing a cast twice changes nothing in a database that upserts.
- A bigger example:
examples/tickets/, a support desk: replies that belong to a ticket without naming it (known), mentions that wait for a lookup, andschemacast pick, which links them to database candidates in one checked call. - The full schema format: the short YAML above is GraFlo's compact notation;
schemacast schema --schema schema.yamlprints the full GraFlo schema it stands for, which SchemaCast also reads directly. - Plain JSON out:
cast --bundlealso writes nodes, edges and quotes as JSON Lines with stable ids, readable without GraFlo. - A service:
schemacast serve(extraserver) offersPOST /castandPOST /pick.
schemacast-bench casts a bundled corpus of texts whose graphs are known and scores the result
exactly, with no model as judge: conformance, hallucination, precision and recall, direction,
spans, mention versus mint, injection, selection and re-cast stability, with tokens and cost. It
runs a corpus of your own the same way (--corpus DIR), and scores saved casts with no model
(schemacast-bench score).
Registry mode is planned: selection across the schemas of a GraFlo schema registry. Today a cast selects within one schema.
growgraph.github.io/SchemaCast: installation, how a cast works, mentions and resolution, groundings and qualifiers, context and known entities, preparing a schema, replay, writing to a database, linking staged mentions, running as a service, the benchmark, and the reference.
uv sync --group dev && uv run pytest # tests
uv run --group docs properdocs serve # the docs siteSee Contributing. Contributors accept the Contributor License Agreement once, by commenting on their first pull request.
Apache-2.0. Maintained by GrowGraph.