
A small knowledge system is now practical to automate and deploy using ordinary software services.
The repetitive work can run in the background: discovering documents, saving versions, finding references, refreshing search and returning evidence to an assistant. An API gives the software a reliable way to ask for source records. A scheduled job repeats the work. A hosted application makes the result available to people.
You can begin with one or two Acts, a small database and a simple search page. An AI coding assistant can help assemble these pieces. The quality of the resulting knowledge still depends on the sources selected, the relationships recorded and the checks applied when something changes.
PCO API → saved source → checked records → updated graph
Question → search and connections → evidence bundle → LLM explanation
The first routine maintains the collection. The second chooses context for each answer.
Start with the New Zealand Legislation API
PCO’s developer guide explains how to request an API key. Store the key in your server’s secret settings as PCO_API_KEY. The server adds it to the X-Api-Key request header. Keep the value out of page code, URLs, source control and logs.
The PCO key authorises source requests. If you add a hosted LLM, its API uses separate access credentials and may have its own usage charges. Your graph’s research API is a third interface, controlled by your application.
PCO’s developer guide and API reference checked 18 November 2026. The service is documented as version 0 beta. Follow its access terms and rate-limit responses.
Try the source-capture step
This starter uses the Fair Trading Act and Consumer Guarantees Act from the supplied example. It lists available versions, then saves the XML for a version you select. It records the source URL, capture time and a file fingerprint so later runs can detect changed content.
A small Python starter
Requires Python 3.10 or newer. It uses the standard library, with no extra packages. Configure PCO_API_KEY in the environment of the process that runs it, then use the commands below.
Checked with simulated responses. Authenticated access has not been run for this guide. This page does not ask for, store or use an API key.
Show the request and commands
The first command makes this request using the key supplied by the server:
GET https://api.legislation.govt.nz/v0/works/act_public_1986_121/versions/
X-Api-Key: <your server-held PCO key>
Accept: application/json# First list the available Fair Trading Act versions.
python3 pco_snapshot.py list fta
# Use an exact version_id returned by that request.
# Replace RETURNED_VERSION_ID below with that identifier.
python3 pco_snapshot.py capture RETURNED_VERSION_ID
# For the Consumer Guarantees Act:
python3 pco_snapshot.py list cgaThe capture command requests /v0/versions/{version_id}/ and follows its XML format link. Keep the returned identifier intact, including any suffix. A download request carries no API key.
The saved folder contains source.xml and manifest.json. The manifest records the work and version IDs, the source link, the capture time, a SHA-256 fingerprint and an unreviewed status. It makes no claim about legal applicability.
Select the version for the purpose of your research. A recent download date does not establish which law applies to an earlier event. PCO’s documentation also explains that a search match can point to an older version; do not silently treat a matching version as the latest one.
Turn the source into a service
Once source capture works, the same pattern can support an automated import. Open each step to see what the software does and what needs a deliberate decision.
Extract the recordsUse the document’s structure.
A parser reads the XML’s structure and separates sections, headings, definitions and references. Store each provision’s identity separately from its text in a particular version. Keep the original file alongside the extracted records.
For the sample graph, a section becomes a node. A reference to another section becomes a candidate edge. Validate the parser against real source files before allowing it to update the collection. The supplied handover includes a prototype adapter whose full XML ingestion remains disabled.
PCO’s XML data guide is the starting reference for that work.
Record connectionsPreserve the evidence for each link.
Software can extract an express cross-reference and attach the words and location that support it. A model can also suggest less explicit connections, such as a related definition or potential qualification.
Keep machine suggestions labelled and send interpretive relationships for review. Save the direction, conditions, source version and review decision. When a source changes, flag the affected links for another check.
The supplied example already demonstrates a modest storage option: SQLite tables for records and relationships. A specialist graph database can be added if the scale and queries justify it.
Give the assistant a toolReturn a useful bundle of evidence.
Create a research endpoint that accepts a question or starting provision, searches the stored records and follows a bounded set of connections. Return relevant text, source links, versions, relationship evidence and gaps in coverage.
Your application can call that endpoint before asking the LLM to answer, or expose it as a tool the assistant can request. The application supplies the returned bundle with the question and asks for a cited explanation. This does not retrain the model.
Try the simulated research request to see the shape of this exchange. That endpoint is a design example; this guide has no live research service.
Deploy the componentsA worker, a store and a web application.
Put the importer on a server or managed job service that can run Python. Give it the PCO key through secret settings and persistent storage for source files. Store the graph in a database the application can query.
Host the search page and research API as a web application. Configure who may use it and which records each user may receive. A small deployment can share one server; larger services can separate the importer, store and application.
Keep persistent files in durable storage. Many hosted functions have temporary local filesystems, so a local SQLite file or downloaded XML can disappear between runs.
Keep it currentRepeat the routine and surface changes.
Set a scheduled job, for example once each night, to check the selected works for new versions. Compare version IDs and file fingerprints, process changed sources and leave unchanged records alone.
Stage updates before making them searchable. Check that extraction completed, references resolve and existing research examples still return the expected evidence. Promote the new collection only after its checks and required reviews pass.
Record the last successful run and show freshness and coverage to the reader. Back off when the source service limits requests; retain the last checked collection if an update fails. Keep snapshots so an update can be reversed.
What is easy to automate?
| Repeatable software work | Decisions and review |
|---|---|
| Discover versions, download files and compare fingerprints. | Choose the collection’s scope and the versions relevant to its purpose. |
| Extract structured references and prepare candidate relationships. | Check meaning, exceptions, commencement and legal applicability. |
| Rebuild search, follow saved connections and assemble context. | Judge whether the evidence is sufficient and the explanation is sound. |
The practical benefit is cumulative: work done to organise a source once can assist many later questions. Automation keeps that work available and brings changes to attention. The LLM receives a clearer, more traceable basis for each answer.
Where this example standsThe interactive graph uses the supplied selected records. The downloadable starter covers source capture only. A validated importer, reviewed corpus, live research API, model connection and scheduled deployment are further implementation steps.