Skip to content

When the model fails ​

Task: a page that uses a model should still work — and say what happened — when the model server is down, slow, or missing the model.

yaml
# Recipe: the page goes on, and says so, when the model cannot answer.
paths:
  components: ./components

llm:
  model: phi3

Without onerror, an AI failure stops the page with an error that names the server and the cause. With onerror="continue", the page goes on: summary_result.success is false, summary_result.error.message says why, and summary is empty. The example points endpoint= at a server that is not running, so it fails the same way everywhere.

xml
<q:component name="Summary">
  <q:set name="text" value="Returns are accepted within 30 days of delivery, with the receipt." />

  <!-- endpoint= sends this one call to another server — here one that is not
       running, to show the failure. onerror="continue": instead of stopping
       the page, the failure is in summary_result and the value is empty. -->
  <q:llm name="summary" endpoint="http://127.0.0.1:9" timeout="5" onerror="continue">
    <q:prompt>Summarize in five words: {text}</q:prompt>
  </q:llm>

  <ui:window title="Policy">
    <ui:text>{text}</ui:text>
    <q:if condition="summary_result.success">
      <ui:text>In short: {summary}</ui:text>
      <q:else>
        <ui:alert variant="info">No summary right now — the assistant is unavailable.</ui:alert>
        <ui:text>Why: {summary_result.error.message}</ui:text>
      </q:else>
    </q:if>
  </ui:window>
</q:component>
xml
<q:test name="the page still renders, and says why" page="/">
  <test:visit />
  <test:expect status="200" />
  <test:expect text="Returns are accepted within 30 days" />
  <test:expect text="No summary right now" />
  <test:expect text="127.0.0.1:9" />
  <test:expect no-text="In short:" />
</q:test>
text
tests/failure.test.q
  PASS  the page still renders, and says why
1 passed, 0 failed

onerror works the same on q:llm, q:knowledge, q:agent and q:query.

See IA-5.

MIT Licensed · Built with VitePress