> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Typed model tasks

> Declare one bounded model call with a checked input and a checked structured output.

`task(ai, spec)` from `@bijectionhq/library-models` declares one bounded
model call: the catalog entry, instructions, an input type, an output type
and the prompt builder.

```ts bijection/triage.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { mutation, t } from "@bijectionhq/bijection";
import { task, type LanguageModel, type Models } from "@bijectionhq/library-models";
import { support, tickets } from "./schema";

declare const ai: Models<{ triage: LanguageModel }>;

export const triage = task(ai, {
  name: "ticket-triage",
  revision: "3",
  model: "triage",
  input: { subject: t.string, body: t.string },
  output: { queue: t.one("billing", "tech"), urgent: t.boolean },
  instructions: "Route the ticket to one queue.",
  prompt: (ticket) => `Subject: ${ticket.subject}\n\n${ticket.body}`,
});

export const classify = mutation(
  { under: support, args: { id: t.key(tickets) } },
  async (ctx, { id }) => {
    const ticket = await ctx.get(tickets(id));
    if (ticket === null) return ctx.refuse("Absent", "no such ticket.");
    await triage.submit(ctx, { subject: ticket.subject, body: ticket.body }, {
      once: ["triage", id],
      then: triaged.with({ id }),
    });
    return null;
  },
);

export const triaged = mutation(
  { under: support, args: { id: t.key(tickets), result: triage.result } },
  async (ctx, { id, result }) => {
    const checked = triage.check(result);
    if (checked.ok) await ctx.patch(tickets(id), checked.value);
    return null;
  },
);
```

* `task.submit(ctx, input, { once, then, within })` refuses input that does
  not conform to `input`.
* `task.check(result)` answers `ok` with the typed value, `InvalidOutput`
  with the first problem and the raw answer, or the call's own refusal.
  The model's answer is untrusted: nothing is written until you check it.
* `task.result` is the type the continuation declares for its `result`.
* `task.definition.digest` covers the name, revision, model entry,
  instructions, both types and the bounds. Store it beside a result to
  know what produced it. The `prompt` function's code is not covered:
  change the revision when it changes.

`jsonSchema(type)` and `problem(type, value)` derive a model contract from
a value type and check a value against it, for your own structured
generations.

## Screen untrusted content

`screen(content, { mode })` runs deterministic rules over text before it
reaches a model: instruction override, role reassignment, system
impersonation, secret exfiltration, tool invocation, markdown exfiltration
and hidden characters. With `mode: "block"`, matched content is withheld
(`verdict.finding`). `screenCheck(verdict)` turns a verdict into a
[`checks`](https://docs.bijection.com/models/review-and-serving#checks) record of kind
`injection-screen`, whose subject is the content's SHA-256: it carries the
digest and the rules, never the content.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.