LaufwerkLaufwerk
Learn Laufwerk

Structured data and real checks

Give the next step a usable contract without confusing valid JSON with a correct answer.

A structured result lets code use an agent's answer. It does not establish that the answer is true. Treat shape validation and acceptance checks as separate steps.

Agent response → schema validation → domain checks → decision
                  usable shape       supported result

Define what the next step needs

review.ts
import { Schema } from "effect";

export const Review = Schema.Struct({
  approved: Schema.Boolean,
  feedback: Schema.String,
  evidence: Schema.Array(Schema.Struct({
    claim: Schema.String,
    source: Schema.String,
  })),
});
export type ReviewResult = typeof Review.Type;

export function canAccept(review: ReviewResult): boolean {
  return review.approved && review.evidence.length > 0;
}

Pass Review as output on Session.run or session.ask. Your result now has boolean approved and an array of evidence entries. canAccept rejects an empty evidence list; it still cannot tell whether the cited source supports the claim. A source-checking step or a person must establish that.

See what the schema rejects

review.test.ts
import { expect, test } from "bun:test";
import { Schema } from "effect";
import { Review, canAccept } from "./review";

test("a valid shape can still fail the acceptance rule", () => {
  const review = Schema.decodeUnknownSync(Review)({
    approved: true, feedback: "Looks good", evidence: [],
  });
  expect(canAccept(review)).toBe(false);
  expect(() => Schema.decodeUnknownSync(Review)({
    approved: "yes", feedback: "Looks good", evidence: [],
  })).toThrow();
});

The first object decodes but fails the domain check. The second object fails schema decoding because "yes" is not a boolean.

Decide what failure means

OutcomeResponse in your workflow
Invalid schemaStop or take an explicit repair branch
Valid negative reviewRevise, decline or escalate according to policy
Provider failurePreserve the error; a review did not complete
Nonzero verification commandReject the candidate using actual command evidence

Laufwerk turns your output schema into prompt guidance and decodes the response. It does not use provider-enforced constrained generation or automatically rerun a failed structured turn: the original turn may already have used tools or edited files. Keep acceptance checks outside the agent's editable material where possible.

Reference: Schema types · Session output semantics


← Sessions and shared files · Next: Branches, loops and parallel work →

On this page