Skip to content

Docs

Cookbook: Structure Recovery

Reconstruct Markdown from unformatted text in two requests: 16 Noul line-pair questions stitch split sentences, then 62 questions classify each block's type and companions.
Format
Docs
Reading time
3 min
Published by
TypeSafe AI
Last verified
Sep 2026

Highlights

  • Two round trips on a 28-line memo: 16 stitch questions then 62 classification questions, 10,211 tokens in 0.8 seconds.
  • Join cutoffs of 0.2 after dangling lines and 0.5 after terminal punctuation healed 11 line breaks.
  • Asking whether a line picks up mid-sentence instead of whether it is the same paragraph kept blocks at 17 rather than collapsing to 12.
  • Type dictionaries act as the whole classifier spec, and companion questions ride the same request.

Quickstart

python
JOIN_AFTER_DANGLING, JOIN_AFTER_TERMINAL = 0.2, 0.5

joins = client.system_one(  # pass 1: 16 Nouls, one per adjacent line pair
    state=tag(LINES, "L"),
    questions={line_id(i): join_question(i) for i in range(1, len(LINES)) if not LINES[i]["gap"]},
    model=TYPESAFE_MODEL,
).answers
blocks = merge([joins[line_id(i)].noul if line_id(i) in joins else 0.0
                for i in range(len(LINES))])
classified = client.system_one(  # pass 2: 62 questions about 17 blocks, one request
    state=tag(blocks, "B"), questions=classify_questions([b["text"] for b in blocks]),
    model=TYPESAFE_MODEL,
)

Watch out

Stitching and typing are two separate judgment layers, so a bad stitch can produce a clean-looking document with the wrong structure.

Questions about this entry

Short answers drawn from the linked project or page.

Reactions & coverage

Posts, threads, and videos about this entry from around the web.

X: 200 rows, 32 template families, and traps, judged in one call

From the Jev guides

Original write-ups on what this entry is for.

From the Jev AI model community

Posts from builders shipping with Jev right now.

Follow @typesafeai