Corrections
POST /v1/corrections — tell LiyaEngine an answer was wrong and what it should have said, so the passages behind it can be flagged for review.
When your application serves answers through the API, nobody steps into a conversation to correct them: there is no support inbox or widget handover. This endpoint is how your application reports a wrong answer. The passages of your knowledge base that the answer was built from are counted against, and three corrections flag a passage for review under Self-healing › Findings › Passages, where a fix can be drafted from the corrections.
A suspicion, not proof
A correction counts against the passages the answer most likely leaned on, so the fault may be in a neighbour. A flag is a reason to look, and nothing is changed for you.
Report a wrong answer
POST https://api.liyaengine.ai/v1/corrections
Authorization: Bearer liya_xxxxxxxxxxxx
Content-Type: application/json
{
"message_id": "msg_xyz",
"correct_answer": "Annual plans can be refunded within 45 days of purchase.",
"note": "Customer used the thumbs-down button",
"end_user_id": "user_001"
}| Field | Notes |
|---|---|
message_id | The message_id an intent call returned in data.message_id. It must be an assistant answer in this workspace. Send this or run_id, not both. |
run_id | The run_id an agent run returned. The run must have finished. See Agent run answers. |
correct_answer | Required, at most 4000 characters. What the answer should have said. Personal details are removed before it is stored. |
note | At most 500 characters. Why, for example a thumbs-down comment. |
end_user_id | At most 200 characters. Your own id for the person who reported it. Never used to identify anyone to LiyaEngine. |
{
"success": true,
"data": {
"correction_id": "cmw...",
"already_recorded": false,
"note": null,
"passages": [
{ "document_id": "479bf31e-...", "file_name": "refund-policy.pdf", "rank": 1, "attribution": "passage", "counted": true, "flagged": false },
{ "document_id": "9c2a4e11-...", "file_name": "returns-process.md", "rank": 3, "attribution": "lower_ranked", "counted": false, "flagged": false }
]
}
}What is counted
A trace keeps the document each retrieved passage came from and the start of the passage's text, not the passage's id. So attribution is deliberate about what it will claim:
An answer is usually built from several passages, and counting against all of them would let a few reports flag a whole neighbourhood. So a correction counts against only the top two passages by the rank the trace recorded (rank, 1 being the best). The rest are not looked at.
attribution: "lower_ranked". Below the top two, so not counted. It is listed so nothing is hidden.attribution: "passage". The kept text matches exactly one stored passage of the document, or the document has a single passage. The correction is counted against that passage.attribution: "document_only". The trace names the document but no single passage can be tied to. The correction is kept as evidence and nothing is counted, so a correction never flags a passage it cannot be tied to.counted: falseon a passage. This conversation had already counted against it. A conversation counts once against a passage, however many of its answers are reported.flagged: true. The passage is flagged for review now.
When nothing was counted, note says why: the answer recorded no retrieved passages, or its passages could not be tied to one stored passage, or the conversation had already counted.
Reporting the same answer again returns 200 with already_recorded: true, updates the correction text and counts nothing a second time. The official SDKs retry 429 and 5xx responses, which is safe here for the same reason.
Agent run answers
Name an agent run's answer with run_id instead of message_id:
{ "run_id": "cmw...", "correct_answer": "Annual plans can be refunded within 45 days." }An agent run keeps no ranked passage list, only the text its knowledge search tool returned. So for a run:
- The passages of the run's last successful knowledge search are used, in the order the tool returned them. A search that found nothing says nothing about the answer, so the one before it is used. The top two are counted against, like any other answer.
- Each passage is tied to a stored passage by its opening text, and only when exactly one stored passage in your workspace starts with it. A passage that matches none (the document changed or was deleted since) or more than one (the same text uploaded twice) counts nothing.
- A run that never searched the knowledge base has no passages. The correction is kept, with a note saying so.
The run's session is the conversation that counts once against a passage.
Deleting a correction
DELETE https://api.liyaengine.ai/v1/corrections/{correction_id}Erases what the correction says (question, reply, correct answer, note, end user id). Needs a full-access key. It does not lower any passage's count: the record that a conversation counted is kept, so a report, a delete and a second report cannot count one conversation twice, and an answer whose correction was deleted cannot be reported again (409 CORRECTION_DELETED). Corrections are erased the same way after correction_retention_days (default 365, see data retention).
What is kept
The question the user asked and the answer the assistant gave are copied when you report, with personal details removed and each clipped to 700 characters, so the evidence is still there if data retention later removes the trace. They are shown beside your correct_answer when someone reviews the flagged passage.
Keys and limits
- A key with the
runtimescope may call it: it spends no model tokens, reads nothing and changes no configuration. That is the key your application's backend should hold. - Public embed tokens are refused with
403 EMBED_TOKEN_NOT_ALLOWED. A token that ships in a browser would let anyone report a false correction. - Rate-limited per workspace like the rest of the API.
Errors
| Status | Code | Meaning |
|---|---|---|
| 400 | INVALID_CORRECTION | A missing or oversized field, neither message_id nor run_id, or both. |
| 401 | UNAUTHORIZED | No valid key. |
| 403 | EMBED_TOKEN_NOT_ALLOWED | Use a secret API key. |
| 404 | MESSAGE_NOT_FOUND | No assistant answer with that message_id in this workspace. |
| 404 | RUN_NOT_FOUND | No agent run with that run_id in this workspace. |
| 409 | RUN_NOT_FINISHED | The agent run is still running, so it has no answer yet. |
In the SDKs
const result = await client.corrections.report({
messageId: run.data.message_id,
correctAnswer: "Annual plans can be refunded within 45 days of purchase.",
endUserId: "user_001",
});// An agent run's answer
await client.corrections.report({ runId: run.runId, correctAnswer: "Annual plans can be refunded within 45 days." });result = client.corrections.report(
message_id=message_id,
correct_answer="Annual plans can be refunded within 45 days of purchase.",
end_user_id="user_001",
)