Show guardrail refusals and stopped answers on the chat page, and the verdict in ctl request

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-10-04 15:13:15 +02:00
1 parent 47e847423d
commit 7e18b8ab53
3 files changed
+41 -2

No files matched your search

+28 -1
View File
@@ -75,6 +75,11 @@ access to it.</p>
</div>
<script>
// The policy a guardrail acted by, when the response says.
function policySuffix(resp) {
const p = resp.headers.get("x-llmgw-guard-policy");
return p ? " " + p : "";
}
// Vanilla, inline, no build step — the same reason the charts are hand-drawn
// SVG. It streams because a chat that hangs for ten seconds and then dumps a
// paragraph feels broken, and on CPU inference ten seconds is normal.
@@ -365,7 +370,19 @@ access to it.</p>
resp = await post();
}
if (!resp.ok) {
out.textContent = "(" + resp.status + ") " + (await resp.text()).slice(0, 400);
const text = await resp.text();
let shown = "(" + resp.status + ") " + text.slice(0, 400);
// Refused by a guardrail: said as what it is, not as a failure.
try {
const e = JSON.parse(text).error;
if (e && e.code === "content_policy_violation") {
const policy = resp.headers.get("x-llmgw-guard-policy");
shown = "Refused by the gateway's policy" + (policy ? " " + policy : "") + ": " + e.message;
} else if (e && e.code === "no_store") {
shown = e.message;
}
} catch (_) { /* not JSON: shown as it came */ }
out.textContent = shown;
out.classList.add("failed");
messages.pop();
return;
@@ -424,6 +441,12 @@ access to it.</p>
dl.onclick = () => downloadCode(reply, dl);
out.after(dl);
}
if (finish === "content_filter") {
const note = document.createElement("p");
note.className = "note truncated";
note.textContent = "Stopped by the gateway's policy" + policySuffix(resp) + ".";
out.after(note);
}
if (finish === "length") {
// Appended as a sibling, never into the reply: out holds model text
// placed with textContent, and this is ours.
@@ -438,6 +461,10 @@ access to it.</p>
await renderReply(out, reply);
renderMath(out);
}
else if (finish === "content_filter") {
out.textContent = "(stopped by the gateway's policy" + policySuffix(resp) + " before anything was shown)";
out.classList.add("failed"); messages.pop();
}
else if (stopped) { out.textContent = "(stopped before anything came back)"; out.classList.add("failed"); messages.pop(); }
else { out.textContent = "(no content came back)"; out.classList.add("failed"); }
} catch (err) {