Suppose we’re building a graph database of company acquisitions. Each company is a node, and an arrow points from the buyer to the company it bought. We’re already asking a language model to read the announcements. Why not ask for the finished database record while we’re at it?
Take the source document ID. If the model changes one digit, the right acquisition ends up attached to the wrong announcement. We already have the ID, so we can fill in that field ourselves. What else can we take out of the prompt?
Let’s make up an announcement about two fictional companies.
North Pier acquired Alder Labs.
Finding “North Pier” and “Alder Labs” and marking both as companies is named entity recognition (NER). Working out which company bought the other is relation extraction. That gives us the direction of the arrow.
I made up the document number and the ID format for this example. The application already knows which document version and chunk it sends to the model.
An RDF graph stores each fact as a triple with a subject, a predicate, and an object. We can ask the model for just the facts it finds in the sentence.
{
"facts": [
["North Pier", "type", "Company"],
["Alder Labs", "type", "Company"],
["North Pier", "acquired", "Alder Labs"]
]
}
Change the sentence to “North Pier was acquired by Alder Labs.” The two company rows stay the same. The last row becomes ["Alder Labs", "acquired", "North Pier"].
Code assigns each mention an ID from the document version and its position within that document. On a retry, the same occurrence of “North Pier” gets the same ID.
Here’s the resulting graph in TriG format. The last line links the extracted facts to their source chunk.
@prefix : <https://example.org/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix prov: <http://www.w3.org/ns/prov#> .
:d17v1-c1-facts {
:d17v1-e0-10 a :Company .
:d17v1-e0-10 rdfs:label "North Pier" .
:d17v1-e20-30 a :Company .
:d17v1-e20-30 rdfs:label "Alder Labs" .
:d17v1-e0-10 :acquired :d17v1-e20-30 .
}
:d17v1-c1-facts prov:wasDerivedFrom :d17v1-c1 .
This works because each name occurs once in our chunk. If “North Pier” appears twice, we need more context to pick the right occurrence.
Before adding an acquisition, the code checks that both companies exist in the graph. That check passes whichever way the arrow points. To tell whether North Pier was the buyer, we have to compare the relationship with the original sentence.
North Pier acquired the mill on lot 4.
The mill has no name here. Should it still get a node? For a directory of named facilities, we can skip it. For someone tracking which assets changed hands, the mill is the point. Our graph would need a Facility type for it.
I’d write down what each user expects before changing the prompt.
| What the text mentions | Named-facility directory | Asset register |
|---|---|---|
| West Mill, Pier Warehouse | Keep | Keep |
| the mill on lot 4, the warehouse at berth 2 | Skip | Keep |
| mills in general, warehouses in general | Skip | Skip |
What about “North Pier met Alder Labs after it bought the mill”? Either firm could be the buyer. An unresolved list gives the model a way to flag “it bought the mill.” An empty list of acquisitions alone would look like a missed purchase.
Suppose we change the prompt to keep unnamed facilities. It now picks up the mill on lot 4. Did it also start adding a facility every time someone writes “mills need water”?
Collect several documents for each case and mark the expected answers. Keep revisions of one announcement in the same set. Edit the prompts on the development set, choose a version of each on the validation set, and save the test set for the final comparison.
I’d compare two prompts. One asks for the full RDF graph. The other asks for the three-column JSON rows. Run each five times per test document with the same model, example sentences, and retry limit.
Compare runs, too. A prompt can name the same wrong buyer five times.
We found the split by working backward from the result we wanted. If the application already has a value or can derive it by a rule, let code fill it in. Ask the LLM for the parts that require interpreting the input, then check its response in code. Test the rules directly. To see whether the model’s judgments match what users expect, try it on examples you kept out of prompt tuning.