curl -X PUT 'https://api.anyformat.ai/v3/document-packets/069dcc2c-e14c-7606-8000-2ee4fb17b4e1/ground-truth/' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"ground_truth": {
"0686bb978c3070f0800097669e00aaaa": "INV-001",
"0686bb978c3070f0800097669e00bbbb": [
{ "0686bb978c3070f0800097669e00cccc": "12.00" }
]
}
}'
from anyformat.sdk import Client
client = Client(api_key="YOUR_API_KEY")
packet_id = "069dcc2c-e14c-7606-8000-2ee4fb17b4e1"
stored = client.get_ground_truth(packet_id)
corrected = {**(stored.ground_truth or {}), "0686bb978c3070f0800097669e00aaaa": "INV-002"}
client.set_ground_truth(packet_id, corrected, version_id=stored.version_id)
import { Anyformat } from "@anyformat/sdk";
const af = new Anyformat({ apiKey: "YOUR_API_KEY" });
const packetId = "069dcc2c-e14c-7606-8000-2ee4fb17b4e1";
const stored = await af.getGroundTruth(packetId);
await af.setGroundTruth(
packetId,
{ ...stored.ground_truth, "0686bb978c3070f0800097669e00aaaa": "INV-002" },
{ versionId: stored.version_id },
);
{
"ground_truth": {
"0686bb978c3070f0800097669e00aaaa": "INV-001",
"0686bb978c3070f0800097669e00bbbb": [
{ "0686bb978c3070f0800097669e00cccc": "12.00" }
]
},
"version_id": "FGaV4I2JAA",
"node_id": "extract_1"
}
{
"error": "The ground truth is not valid.",
"detail": [
{
"type": "missing",
"loc": ["0686bb978c3070f0800097669e00bbbb", 0, "0686bb978c3070f0800097669e00cccc"],
"msg": "Field required"
}
],
"error_code": "GT_INVALID",
"retryable": false,
"request_id": "req_abc123",
"doc_url": "https://docs.anyformat.ai/api-reference-v3/errors#error-code-gt_invalid",
"recovery": "Correct the ground truth against `detail` so it matches the workflow's fields, and upload it again."
}
Set Ground Truth
Create or replace one dataset document’s complete ground truth
curl -X PUT 'https://api.anyformat.ai/v3/document-packets/069dcc2c-e14c-7606-8000-2ee4fb17b4e1/ground-truth/' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"ground_truth": {
"0686bb978c3070f0800097669e00aaaa": "INV-001",
"0686bb978c3070f0800097669e00bbbb": [
{ "0686bb978c3070f0800097669e00cccc": "12.00" }
]
}
}'
from anyformat.sdk import Client
client = Client(api_key="YOUR_API_KEY")
packet_id = "069dcc2c-e14c-7606-8000-2ee4fb17b4e1"
stored = client.get_ground_truth(packet_id)
corrected = {**(stored.ground_truth or {}), "0686bb978c3070f0800097669e00aaaa": "INV-002"}
client.set_ground_truth(packet_id, corrected, version_id=stored.version_id)
import { Anyformat } from "@anyformat/sdk";
const af = new Anyformat({ apiKey: "YOUR_API_KEY" });
const packetId = "069dcc2c-e14c-7606-8000-2ee4fb17b4e1";
const stored = await af.getGroundTruth(packetId);
await af.setGroundTruth(
packetId,
{ ...stored.ground_truth, "0686bb978c3070f0800097669e00aaaa": "INV-002" },
{ versionId: stored.version_id },
);
{
"ground_truth": {
"0686bb978c3070f0800097669e00aaaa": "INV-001",
"0686bb978c3070f0800097669e00bbbb": [
{ "0686bb978c3070f0800097669e00cccc": "12.00" }
]
},
"version_id": "FGaV4I2JAA",
"node_id": "extract_1"
}
{
"error": "The ground truth is not valid.",
"detail": [
{
"type": "missing",
"loc": ["0686bb978c3070f0800097669e00bbbb", 0, "0686bb978c3070f0800097669e00cccc"],
"msg": "Field required"
}
],
"error_code": "GT_INVALID",
"retryable": false,
"request_id": "req_abc123",
"doc_url": "https://docs.anyformat.ai/api-reference-v3/errors#error-code-gt_invalid",
"recovery": "Correct the ground truth against `detail` so it matches the workflow's fields, and upload it again."
}
201, a replace answers 200, and both return the stored document in the shape Get ground truth returns.
Send the complete document in ground_truth: every field of the workflow must be present. A list field may be [] and any value may be null. Keys are the workflow schema’s field identifiers: use persistent_id (the API also accepts sanitized_name). The stored document is always keyed by persistent_id. A scalar field maps to string | null; a table or object field maps to an array of row objects keyed the same way.
Omit version_id to write to the workflow’s current version, the one an eval grades by default. node_id is the extract node’s id in the workflow graph, required only when the version has more than one extract node.
Only a dataset document packet holds ground truth. A production packet answers 409 NOT_IN_DATASET: upload the document to the dataset and set ground truth on the packet it returns.
Errors
| Status | error_code | When |
|---|---|---|
403 | ACCESS_DENIED | The key’s user is a Viewer of the organization. |
403 | insufficient_api_key_scope | The API key has no write scope. |
404 | NOT_FOUND | params.resource_type is document_packet (unknown, or in another organization) or workflow_version. |
409 | NOT_IN_DATASET | The packet is not a dataset document. |
409 | ZERO_DATA_RETENTION_REFUSES_DATASET | The organization keeps no data, so it has no dataset. |
422 | GT_INVALID | detail lists each offending key as { type, loc, msg }; loc is the path to it, such as ["line_items", 0, "sku"]. |
422 | EXTRACT_NODE_UNRESOLVED | The version has more than one extract node and no node_id was sent, or node_id names no extract node. |
curl -X PUT 'https://api.anyformat.ai/v3/document-packets/069dcc2c-e14c-7606-8000-2ee4fb17b4e1/ground-truth/' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"ground_truth": {
"0686bb978c3070f0800097669e00aaaa": "INV-001",
"0686bb978c3070f0800097669e00bbbb": [
{ "0686bb978c3070f0800097669e00cccc": "12.00" }
]
}
}'
from anyformat.sdk import Client
client = Client(api_key="YOUR_API_KEY")
packet_id = "069dcc2c-e14c-7606-8000-2ee4fb17b4e1"
stored = client.get_ground_truth(packet_id)
corrected = {**(stored.ground_truth or {}), "0686bb978c3070f0800097669e00aaaa": "INV-002"}
client.set_ground_truth(packet_id, corrected, version_id=stored.version_id)
import { Anyformat } from "@anyformat/sdk";
const af = new Anyformat({ apiKey: "YOUR_API_KEY" });
const packetId = "069dcc2c-e14c-7606-8000-2ee4fb17b4e1";
const stored = await af.getGroundTruth(packetId);
await af.setGroundTruth(
packetId,
{ ...stored.ground_truth, "0686bb978c3070f0800097669e00aaaa": "INV-002" },
{ versionId: stored.version_id },
);
{
"ground_truth": {
"0686bb978c3070f0800097669e00aaaa": "INV-001",
"0686bb978c3070f0800097669e00bbbb": [
{ "0686bb978c3070f0800097669e00cccc": "12.00" }
]
},
"version_id": "FGaV4I2JAA",
"node_id": "extract_1"
}
{
"error": "The ground truth is not valid.",
"detail": [
{
"type": "missing",
"loc": ["0686bb978c3070f0800097669e00bbbb", 0, "0686bb978c3070f0800097669e00cccc"],
"msg": "Field required"
}
],
"error_code": "GT_INVALID",
"retryable": false,
"request_id": "req_abc123",
"doc_url": "https://docs.anyformat.ai/api-reference-v3/errors#error-code-gt_invalid",
"recovery": "Correct the ground truth against `detail` so it matches the workflow's fields, and upload it again."
}
Authorizations
API key issued from app.anyformat.ai/api-key. Send as Authorization: Bearer <key>.
Path Parameters
Body
Body for PUT /v3/document-packets/{document_packet_id}/ground-truth/.
The complete expected document. Keys are the workflow schema's field identifiers: advertise persistent_id (the API also accepts sanitized_name). A scalar field maps to string | null; a table or object field maps to an array of row objects. Every field must be present; a list field may be [].
{
"0686bb978c3070f0800097669e00aaaa": "INV-001"
}
A version_id from GET /v3/workflows/{workflow_id}/versions/. Omit it for the workflow's current version, the one an eval grades by default.
"FGaV4I2JAA"
The extract node's id in the workflow graph, as GET /v3/workflows/{workflow_id}/ returns it. Required only when the version has more than one extract node.
"extract_1"
Response
Successful Response
A document packet's stored ground truth and the (version, node) it belongs to.
The expected document, keyed by the workflow's field persistent_ids. A scalar field maps to string | null; a table or object field maps to an array of row objects keyed the same way. null until ground truth is first set for this version and node.
{
"0686bb978c3070f0800097669e00aaaa": "INV-001"
}
The workflow version the ground truth belongs to.
"FGaV4I2JAA"
The extract node's id in the workflow graph.
"extract_1"

