Structure Recovery: Restoring Plain Text into Markdown
💡 One-sentence summary: Use Jev to convert plain text to Markdown — decide line breaks and block types, let the code stitch lines and add Markdown markers, and don't let format restoration casually turn into rewriting the body text.
What You Will Be Able to Do After This Lesson
- Find sentences in plain text that were split apart by hard line breaks.
- Explain why this example needs two requests: stitch lines first, then classify.
- Distinguish body text, headings, lists, quotes, code, and callout blocks.
- Verify results by comparing against the source text and checking low confidence, not just by whether the layout looks pretty.
Why use Jev instead of having a generative model rewrite directly?
The two approaches have different goals. This lesson only discusses the official autoformat example and does not rank model effectiveness based on it.
| Check item | The route of directly generating Markdown | The Jev route in this example |
|---|---|---|
| Body text source | ❌ Must check whether the generation process changed the wording | ✅ The renderer uses the input text blocks |
| Model task | ❌ Decides structure and outputs text at the same time | ✅ Answers narrow questions such as line breaks and block types |
| Layout generation | ❌ The model outputs the Markdown | ✅ The code adds the markers |
| Uncertainty | ❌ Requires a separately designed verification method | ✅ Preserves the probability information in the judgment results |
This is not a byte-for-byte lossless conversion. The official preprocessing normalizes whitespace, strips leading and trailing whitespace, and adds spaces when stitching lines; rendering also adds new Markdown markers.
Your Current Dilemma
A copied email keeps its line breaks but loses headings and bullet points. Merging all adjacent lines directly squeezes the list into the previous sentence; keeping every line separate shatters a normal paragraph.
Narrow the question first: is this line the continuation of a sentence broken off midway in the previous line? This is closer to the decision you actually need to make than judging "is it the same paragraph."
When to use this technique
It suits plain text where the body text survives but structural markers are lost. The official demo is a build-system migration memo.
It is not an OCR, fact-correction, or content-completion tool. If the input itself is missing characters, has scrambled order, or has broken code indentation, you should keep the original and arrange manual review instead of promising to automatically restore the author's intent.
🎒 Preparation Before You Start
First, understand the Choice question type and the Noul question type. The code in this lesson is taken verbatim from the official Structure recovery example; copying it in order is enough to run it.
The official installation command (cooksafe is the official companion tool library, providing the JsonCache cache and Playground link helpers used in this lesson):
pip install ipython 'cooksafe>=0.2.0,<0.3.0'Download the cache from the official autoformat example directory into the directory where you run the script (replaying the officially recorded numbers depends entirely on it):
curl -sL -o json_cache.json https://raw.githubusercontent.com/typesafe-ai/typesafe-public-examples/main/cookbooks/autoformat/json_cache.jsonThe official code builds the client from the TYPESAFE_API_KEY environment variable; do not write a real key into notes or articles; when only replaying the cache, setting a placeholder value is enough (see Step 1). The code also imports IPython's display functionality (used when the official ending generates the Playground link); every step of this lesson runs in a plain Python script. If you do not place the cache file, everything becomes a live request and requires valid credentials.
The cache does not mean free runs of arbitrary input
The official cache is for replaying matching example calls. After changing the input or the questions, you cannot assume it still hits, and you should not call a single cache replay a real-world test result of a new model. This lesson makes no paid live calls.
Follow Along
First, let's set up how to run it: create a new autoformat.py, paste the code block of each step below in order into the same file, and run python autoformat.py once after completing each step. The code is taken verbatim from the official example; the only adjustment is defining the official appendix's comparison question naive_join_question in advance (it is needed for the comparison experiment in Step 3). When json_cache.json is in place, every call in this lesson hits the cache and replays the officially recorded answers and latency numbers verbatim, with no real requests made.
Step 1: Prepare the source text and define the boundary of plain-text-to-Markdown conversion
Why: only by fixing the original first can you tell whether the end result restores the format or quietly changes the content.
Paste in the official Setup code — client, cache, model version:
import os
import re
import urllib.request
from pathlib import Path
from time import perf_counter
from cooksafe import JsonCache, make_playground_link
from IPython.display import Markdown, display
from typesafe_sdk import Choice, Noul, NoulCriteria, TypeSafeClient
TYPESAFE_MODEL = "jev-1.12"
client = TypeSafeClient(api_key=os.environ["TYPESAFE_API_KEY"], timeout=120.0)
json_cache = JsonCache(Path("json_cache.json"))os.environ["TYPESAFE_API_KEY"] raises an error directly when the variable is not set. When only replaying the cache, setting a placeholder value is enough, for example export TYPESAFE_API_KEY=cache-only — a cache hit makes no real request.
Then paste in the official code for downloading the source text (@json_cache makes this download replayable too):
DOCUMENT_URL = (
"https://raw.githubusercontent.com/typesafe-ai/typesafe-public-examples/main/cookbooks/autoformat/build-memo.txt"
)
@json_cache
def fetch_document(url: str) -> str:
request = urllib.request.Request(url, headers={"User-Agent": "typesafe-cookbook/1.0"})
with urllib.request.urlopen(request) as response:
return response.read().decode()
RAW = fetch_document(DOCUMENT_URL)
print(RAW[:560])Run python autoformat.py.
You should see: the beginning of a memo without Markdown heading or list markers, not an already formatted article:
Migration to the new build system
Hi everyone, quick heads up about the build system migration that is
happening next week. We have been running the new pipeline in shadow
mode for three weeks and the results look solid, so it is time to
make the switch for real.Further along: the subheading What changes for you, a standalone line of bun run build, two lists without bullets, and a warning paragraph without any markers — headings, lists, and all such markers are lost, but the blank lines remain (Step 2 will use exactly this evidence).
On the first run, do not replace the input or modify the classification rules; get the public example working first. All subsequent judgments revolve around this one source text, build-memo.txt.
Step 2: Preserve blank-line evidence and inspect line breaks
Why: blank lines are structural information the code can read directly, so there is no need to make the model guess again.
Paste in the official to_lines and line-numbering code. It normalizes whitespace, keeps a marker of whether a blank line exists between adjacent pieces of text, and assigns numbers starting with L to non-empty lines:
def to_lines(text: str) -> list[dict]:
lines, gap = [], False
for raw in text.split("\n"):
stripped = re.sub(r"[\t ]+", " ", raw).strip()
if not stripped:
gap = bool(lines) # a leading blank is not a break
continue
lines.append({"text": stripped, "gap": gap})
gap = False
return lines
def tag(items: list[dict], prefix: str) -> str:
return "\n".join(
f"{chr(10) if item['gap'] else ''}{prefix}{i:03d}| {item['text']}"
for i, item in enumerate(items)
)
def line_id(i: int) -> str:
return f"L{i:03d}"
def block_id(i: int) -> str:
return f"B{i:03d}"
LINES = to_lines(RAW)
print(f"{len(LINES)} non-blank lines. The model sees, e.g.:")
print("\n".join(tag(LINES, "L").splitlines()[19:24]))Run it.
You should see (official example output):
28 non-blank lines. The model sees, e.g.:
L013| The cutover touches three teams, so check whether you are on this
L014| list before you plan anything for Monday:
L015| The platform team
L016| The web client team
L017| Whoever still owns the release toolingThe official example has 28 non-empty lines — this is just a checkpoint for that input, not a count your own document must reach. What the model reads is the text with L numbers, and both the questions and answers refer to lines by number.
Step 3: Use Noul to decide whether a sentence continues
Why: only by first restoring sentences split apart by hard line breaks can the subsequent block classification get correct input.
Paste in the official Pass 1 question-construction code. Each pair of adjacent lines not separated by a blank line corresponds to one Noul question, and these questions go into the same request; naive_join_question is the official appendix's comparison question, which the comparison experiment at the end of this step will use:
def join_question(i: int) -> Noul:
return Noul(
instructions=f"Does line {line_id(i)} pick up mid-sentence, continuing a sentence left unfinished at the end of line {line_id(i - 1)}?",
criteria=NoulCriteria(
true="The line starts in the middle of a sentence that began on the previous line - the line break tore the sentence apart",
false="The line begins a new sentence, item, heading, or thought of its own",
),
)
def naive_join_question(i: int) -> Noul:
return Noul(
instructions=f"Are lines {line_id(i - 1)} and {line_id(i)} part of the same paragraph?",
criteria=NoulCriteria(
true="The two lines belong to the same paragraph of running text",
false="The two lines belong to different paragraphs or different pieces of content",
),
)Paste in the official request and line-stitching code — stitch() puts all line pairs into a single request, and merge() stitches continuing lines into blocks according to a threshold:
@json_cache
def stitch(wording: str = "mid-sentence") -> dict:
make = join_question if wording == "mid-sentence" else naive_join_question
questions = {line_id(i): make(i) for i in range(1, len(LINES)) if not LINES[i]["gap"]}
started = perf_counter()
response = client.system_one(
state=tag(LINES, "L"), questions=questions, model=TYPESAFE_MODEL
)
return {
"joins": [
response.answers[line_id(i)].noul if line_id(i) in response.answers else 0.0
for i in range(len(LINES))
],
"seconds": round(perf_counter() - started, 2),
"usage": [response.usage.input_tokens, response.usage.output_tokens],
}
result = stitch()
print(f"{sum(1 for l in LINES if not l['gap']) - 1} pair questions, one request, "
f"{result['seconds']}s")JOIN_AFTER_DANGLING, JOIN_AFTER_TERMINAL = 0.2, 0.5
def ends_terminal(text: str) -> bool:
return re.search(r'[.!?:;…]["\')\]]*$', text) is not None
def merge(joins: list[float]) -> list[dict]:
blocks = []
for i, line in enumerate(LINES):
bar = (
JOIN_AFTER_TERMINAL
if i and ends_terminal(LINES[i - 1]["text"])
else JOIN_AFTER_DANGLING
)
if blocks and not line["gap"] and joins[i] >= bar:
blocks[-1]["text"] += " " + line["text"]
blocks[-1]["lines"].append(i)
else:
blocks.append({"text": line["text"], "lines": [i], "gap": line["gap"]})
return blocks
blocks = merge(result["joins"])
healed = len(LINES) - len(blocks)
print(f"{len(LINES)} lines -> {len(blocks)} blocks ({healed} line breaks healed)")
for i, block in enumerate(blocks):
n = len(block["lines"])
print(f"{block_id(i)} {n} line{'s' if n > 1 else ' '} {block['text'][:62]}")Run it.
You should see (officially recorded output, excerpt; when replaying the cache, the latency numbers also come from the recording):
16 pair questions, one request, 0.32s
28 lines -> 17 blocks (11 line breaks healed)
B000 1 line Migration to the new build system
B001 4 lines Hi everyone, quick heads up about the build system migration t
B002 1 line What changes for you
B003 3 lines The old make targets keep working until the end of the month.
B004 1 line bun run build
……
B014 3 lines If the doctor script reports a red result on the toolchain che
B015 2 lines As Dana put it in the kickoff, "a migration nobody notices is
B016 1 line Thanks, and shout if anything looks off.The official cached example merges 28 lines into 17 blocks. Live request output is not promised to be exactly identical to the cache; when results differ, first check the input, the question phrasing, and how the cache is used—do not directly change the expected numbers.
Why do we still need code rules here
The official merge logic distinguishes whether the previous line ends with terminal punctuation, using different thresholds (0.2 when the previous line has no terminal punctuation, raised to 0.5 when it does); you cannot join two lines just because the content seems "related." These thresholds are that example's choice, not a universally optimal value for all languages and documents.
**Controlled experiment: don't swap the question for "do these belong to the same paragraph?". ** The official appendix re-ran line joining with naive_join_question—under the broad phrasing, list items on the same topic scored 0.77–0.91, the name list was merged into the lead-in sentence, and the 17 blocks shrank to 12 blocks:
naive = stitch("same-paragraph")
print(f"{'':14}{'mid-sentence':>13}{'same paragraph':>16}")
for i in (15, 16, 17, 20, 21):
print(f"{line_id(i)}{'':2}{LINES[i]['text'][:36]:<38}"
f"{result['joins'][i]:>7.2f}{naive['joins'][i]:>13.2f}")
print(f"\nblocks after merge: {len(blocks)} (mid-sentence) vs "
f"{len(merge(naive['joins']))} (same paragraph)") mid-sentence same paragraph
L015 The platform team 0.22 0.77
L016 The web client team 0.11 0.81
L017 Whoever still owns the release tooli 0.12 0.78
L020 Delete the old build cache directory 0.08 0.88
L021 Run the doctor script and fix anythi 0.05 0.91
blocks after merge: 17 (mid-sentence) vs 12 (same paragraph)"Is it the same paragraph?" asks about topic continuity, while "Is this a sentence continuing the previous line?" asks about the text itself. When the judgment feeds into a threshold, the question should name the narrowest fact—here, the difference in phrasing is the difference between 17 blocks and 12 blocks.
Step 4: Classify the already-formed blocks with Choice
Why: blocks only exist after the line-joining results come out, so classification cannot be merged into the same request as the first-pass merging.
Paste in the official Pass 2 classification criteria. Block types include heading, paragraph, list_item, quote, code, callout; the official docs state that these three dictionaries (plus the yes/no judgment for the step question) are the classifier's entire specification—to adapt it to your own documents, these descriptions are what you change:
TYPE_CRITERIA = {
"heading": "A short label or title that names the document or the section that follows it - not a full sentence of content",
"paragraph": "Running prose: one or more complete sentences of explanatory or narrative text",
"list_item": "One entry in a list of parallel items - an ingredient, a feature, a task, an attendee; reads as one of several sibling entries",
"quote": "Words attributed to a person or source - quoted speech, a citation, an excerpt someone else wrote",
"code": "Computer code, a shell command, terminal output, or a config snippet meant to be read verbatim",
"callout": "A warning, tip, or important note that interrupts the flow to flag something the reader must not miss",
}
HLEVEL_CRITERIA = {
"title": "The title of the whole document",
"section": "A major section heading within the document",
"subsection": "A minor heading nested under a section",
}
CALLOUT_CRITERIA = {
"note": "Neutral extra information the reader should be aware of",
"tip": "A helpful suggestion or shortcut that makes things easier",
"warning": "A caution about something that can go wrong or cause harm",
}Paste in the official question-construction code. The same classification request also asks in advance about heading level, whether the list has step ordering, and the callout category—since the type is unknown beforehand, waiting for it would require a third round trip, so the auxiliary questions are asked first; the renderer only uses auxiliary answers relevant to the final block type, and does not treat every auxiliary judgment as a valid label:
HEADING_MAX_CHARS = 90 # longer blocks can't render as headings, so don't ask
def classify_questions(texts: list[str]) -> dict:
questions = {}
for i, text in enumerate(texts):
bid = block_id(i)
questions[f"type_{bid}"] = Choice(
instructions=f"What kind of content is block {bid}?", criteria=TYPE_CRITERIA
)
if len(text) <= HEADING_MAX_CHARS:
questions[f"hlevel_{bid}"] = Choice(
instructions=f"As a heading, what level would block {bid} occupy in this document's structure?",
criteria=HLEVEL_CRITERIA,
)
questions[f"step_{bid}"] = Noul(
instructions=f"Is block {bid} an instruction in a sequence where the order of the items matters?",
criteria=NoulCriteria(
true="It is one step of a procedure - the items around it must happen in order",
false="Order is irrelevant - it is a loose collection, or not a list item at all",
),
)
questions[f"callout_{bid}"] = Choice(
instructions=f"What kind of aside is block {bid}?", criteria=CALLOUT_CRITERIA
)
return questionsPaste in the official classification request and printing code:
@json_cache
def classify(texts: list[str], gaps: list[bool]) -> dict:
tagged = tag([{"text": t, "gap": g} for t, g in zip(texts, gaps)], "B")
questions = classify_questions(texts)
started = perf_counter()
response = client.system_one(state=tagged, questions=questions, model=TYPESAFE_MODEL)
judgments = []
for i in range(len(texts)):
bid = block_id(i)
type_answer = response.answers[f"type_{bid}"]
hlevel = response.answers.get(f"hlevel_{bid}")
judgments.append(
{
"type": type_answer.choice,
"confidence": type_answer.confidence,
"probabilities": type_answer.probabilities,
"hlevel": hlevel.choice if hlevel else "section",
"step": response.answers[f"step_{bid}"].noul,
"callout": response.answers[f"callout_{bid}"].choice,
}
)
return {
"judgments": judgments,
"n_questions": len(questions),
"seconds": round(perf_counter() - started, 2),
"usage": [response.usage.input_tokens, response.usage.output_tokens],
}
classified = classify([b["text"] for b in blocks], [b["gap"] for b in blocks])
for block, judgment in zip(blocks, classified["judgments"]):
block.update(judgment)
print(f"{classified['n_questions']} questions about {len(blocks)} blocks, one request, "
f"{classified['seconds']}s\n")
print(f"{'block':<6}{'type':<11}{'conf':<6}{'companion used':<18}text")
for i, b in enumerate(blocks):
companion = {
"heading": f"level={b['hlevel']}",
"list_item": f"step={b['step']:.2f}",
"callout": f"kind={b['callout']}",
}.get(b["type"], "-")
print(f"{block_id(i):<6}{b['type']:<11}{b['confidence']:.2f} {companion:<18}"
f"{b['text'][:46]}")Run it.
You should see (official recorded output, excerpted):
62 questions about 17 blocks, one request, 0.51s
block type conf companion used text
B000 heading 0.99 level=title Migration to the new build system
B001 paragraph 0.98 - Hi everyone, quick heads up about the build sy
B002 heading 0.75 level=section What changes for you
B003 paragraph 0.89 - The old make targets keep working until the en
B004 code 1.00 - bun run build
B005 paragraph 0.90 - Generated artifacts no longer need to be commi
……
B014 callout 0.65 kind=warning If the doctor script reports a red result on t
B015 quote 0.99 - As Dana put it in the kickoff, "a migration no
B016 paragraph 0.92 - Thanks, and shout if anything looks off.Each block has a type and corresponding judgment records; heading blocks provide the level, and list blocks provide the ordering judgment. Note the step probabilities of the two lists: the three to-do items are at 0.86–0.90 (Step 5 will render them as a numbered list), and the three team-name items are at 0.12–0.16 (rendered as a bulleted list). Do not repeatedly call the API just to reproduce the latency numbers in the document.
Step 5: Render Markdown and compare against the original
Why: correct judgments don't guarantee the final presentation meets your needs—you still have to check the rendering and the content.
Paste in the official rendering code. to_markdown(blocks) groups consecutive list items, uses numbering when the group's mean step probability reaches 0.5, otherwise uses bullets, and adds markers for headings, code, quotes, and callouts (the code contains triple-backtick strings, so this code block is fenced with four backticks):
STEP_THRESHOLD = 0.5
HEADING_MARK = {"title": "#", "section": "##", "subsection": "###"}
CALLOUT_MARK = {"note": "NOTE", "tip": "TIP", "warning": "WARNING"}
def to_markdown(blocks: list[dict]) -> str:
groups = []
for b in blocks:
if b["type"] in ("list_item", "code") and groups and groups[-1][0] == b["type"]:
groups[-1][1].append(b)
else:
groups.append((b["type"], [b]))
parts = []
for kind, items in groups:
if kind == "list_item":
ordered = sum(b["step"] for b in items) / len(items) >= STEP_THRESHOLD
parts.append("\n".join(
f"{n + 1}. {b['text']}" if ordered else f"- {b['text']}"
for n, b in enumerate(items)
))
elif kind == "code":
parts.append("```\n" + "\n".join(b["text"] for b in items) + "\n```")
elif kind == "heading":
parts.append(f"{HEADING_MARK[items[0]['hlevel']]} {items[0]['text']}")
elif kind == "quote":
parts.append(f"> {items[0]['text']}")
elif kind == "callout":
parts.append(f"> [!{CALLOUT_MARK[items[0]['callout']]}]\n> {items[0]['text']}")
else:
parts.append(items[0]["text"])
return "\n\n".join(parts) + "\n"
markdown = to_markdown(blocks)
print(markdown)Run it; first read the printed Markdown, then look at the rendered result.
You should see (official recorded output, excerpted—the opening paragraph with four hard line breaks was merged into one paragraph, commands went into a code fence, one of the two lists is numbered and the other bulleted, and the warning without any markers became a callout block):
# Migration to the new build system
Hi everyone, quick heads up about the build system migration that is happening next week. We have been running the new pipeline in shadow mode for three weeks and the results look solid, so it is time to make the switch for real.
……
```
bun run build
```
……
- The platform team
- The web client team
- Whoever still owns the release tooling
## Things to do before Monday
1. Update your local toolchain to version 2.4 or later
2. Delete the old build cache directory
3. Run the doctor script and fix anything it flags
> [!WARNING]
> If the doctor script reports a red result on the toolchain check, do not proceed with the migration. Ping the infra channel first and we will sort it out together.
> As Dana put it in the kickoff, "a migration nobody notices is the only kind worth shipping."
Thanks, and shout if anything looks off.Headings are no longer mixed into ordinary paragraphs, lists and action steps are presented as appropriate lists, and the commands in the example are displayed as text. Commands in the document are content to be formatted, not system operations for you to execute.
Verify block by block that the original information is still there; pay special attention to the colons before lists, sentences spanning lines, list boundaries, and code. For blocks with low confidence or hard-to-distinguish multiple types, prioritize manual review—in the official example, the lowest-confidence block is precisely the list lead-in sentence (0.43, with paragraph / list_item / callout probabilities scattered at 0.53 / 0.24 / 0.19), and the review-line example the officials give flags blocks whose type confidence is below 0.55 for manual handling.
💡 This is the unique value of Jev
Every character of the output comes from the input: the model only answered narrow questions like "does this line continue a sentence" and "what type is this block"; boundaries, types, and markers are all decided by code. Compare this with letting a generative model rewrite directly—you would then need another way to check whether it changed the wording along the way.
📋 Magic Prompts
The first two are copyable SDK question templates for this lesson's pipeline (placeholders use 【】; those with ? are optional), and the last two are text templates for manual verification—none of them is proof of results from an actually run model.
📝 Line-joining question (Noul version)
Expected effect: when joining lines in your own document, copy this question for every pair of adjacent lines and put them all into a single request; write the judgment criteria as textual facts, not topic continuity.
from typesafe_sdk import Noul, NoulCriteria
# 必填项:【i】是当前行号;true/false 是给模型看的判断标准
join_q = Noul(
instructions=f"Does line {line_id(【i】)} pick up mid-sentence, continuing a "
f"sentence left unfinished at the end of line {line_id(【i - 1】)}?",
criteria=NoulCriteria(
true="【这一行从上一行没写完的句子中间开始——换行把句子拆断了】",
false="【这一行自己开始新的句子、条目、标题或意思】",
),
)
# 选填项:官方 ends_terminal 只认英文标点,处理中文文档时把全角标点补进正则?
# 输出规范:answer.noul 是「接着上一行」的概率,拼不拼由代码按阈值决定
# 约束条件:
# ✅ 问「是否接续句子」这种窄事实——官方对照:换成「同一段落」,列表项得分 0.77–0.91,17 块并成 12 块
# ✅ 空行隔开的行对跳过不发;上一行结尾有无标点由代码读,两档阈值分开设
# ❌ 别让模型输出拼接后的文本——拼接由代码做,输出每个字都来自输入✅ Block-type question (Choice version)
Expected effect: turn "what content is this block" into a multiple-choice question; to adapt it to your own documents, change the description text—the officials say these three dictionaries are the classifier's entire specification.
from typesafe_sdk import Choice
# 必填项:criteria 的键是类型名,值是给模型看的判断标准
type_q = Choice(
instructions=f"What kind of content is block {【块编号】}?",
criteria={
"heading": "【短标签或标题,命名文档或其后章节——不是完整句子】",
"paragraph": "【成段散文:一句或多句完整的说明或叙述】",
"list_item": "【平行条目列表中的一条,读起来是同类的兄弟条目】",
# 官方还有 quote / code / callout 三类,按同样格式补齐
},
)
# 选填项:辅助题(标题层级 / 步骤顺序 / 提示块类别)提前放进同一请求,答案只在类型相关时读?
# 输出规范:answer.choice 是类型名;answer.confidence 和 probabilities 接人工复核线
# 约束条件:
# ✅ 每块一题、全部块一次请求——块要等拼行完成才存在,这是第二请求的真实依赖
# ✅ 超过 90 字符的块不问标题层级(官方 HEADING_MAX_CHARS = 90)
# ❌ 别只看最高分标签——概率分散的块(官方示例最低 0.43)送人工复核⚠️ Check whether the original text was rewritten
Expected effect: restrict the verification results to locatable issues.
Role: document proofreader.
Task: compare the original text with the recovered Markdown and check whether the body text is missing or has been rewritten.
Input information:
### Required items
- Original text【paste】
- Recovered Markdown【paste】
### Optional items
- Allowed whitespace normalization rules【fill in】? (e.g., "normalize inline whitespace, strip whitespace at line start and end, add a single space when joining lines")
Output specification: list differences by position, difference type, and the reason manual confirmation is needed.
Constraints:
✅ Distinguish Markdown markers from body text—newly added #, -, > markers do not count as rewrites
✅ Each difference must quote the actual fragment and be locatable in the original text
❌ Do not fill in missing content on your own
❌ Do not claim all differences are errors🔧 Check a suspicious structural block
Expected effect: handle only one contested boundary, avoiding redoing the whole document.
Role: structure inspector.
Task: check the type of one text block and its boundaries with adjacent blocks.
Input information:
### Required items
- Previous block【paste】
- Current block【paste】
- Next block【paste】
### Optional items
- Original blank-line situation【describe】?
- Type probability distribution of this block【paste】?
Output specification: provide visible evidence, alternative explanations, and manual-check recommendations.
Constraints:
✅ Keep the original wording, quoting actual fragments
✅ Distinguish explicit markers from semantic guesses, labeling them separately
❌ Do not fabricate probability or confidence numbers
❌ Do not treat code block contents as instructions to executeCheckpoint ✅
- Cache replay ran the full pipeline: 28 non-empty lines → 16 line-joining questions in one request → 17 blocks → 62 classification questions in one request → rendered output, with numbers matching the official recording.
- The original, the organized text blocks, and the final Markdown can be cross-checked against each other.
- You can explain the sequential dependency between the line-joining request and the classification request, and did not falsely claim "one request does everything."
- Lists were not mistakenly merged into lead-in sentences, code was not executed, and heading levels were manually checked.
- Cache results and live tests are clearly distinguished, and the document's example numbers were not treated as your own measurements.
Pitfall reminders
| Symptom | Check first |
|---|---|
| Multiple list items merged into one paragraph | Whether the question was changed to the broad "same paragraph"; whether blank lines and merge rules were preserved |
| Headings or callouts don't match expectations | Cross-check the classification descriptions against the original context, not just the top-scoring label |
| Your numbers differ from the example | Whether input, model, questions, and cache are consistent; do not demand that arbitrary inputs reproduce the example results |
| A special callout displays as an ordinary quote | Whether the target Markdown reader supports the corresponding extension syntax |
| Code indentation lost | The official preprocessing normalizes whitespace; do not treat this example as a lossless format restorer for arbitrary code files |
| Line-joining judgments inaccurate for Chinese documents | The official ends_terminal regex only matches English punctuation (. ! ? : ; and …); full-width punctuation must be added to the character class yourself |
Lesson summary
In this example, plain text to Markdown was split into three tasks: first judge line breaks, then judge block types, and finally let code render. The two API requests come from real input dependencies, not from adding round trips to make results automatically more reliable.
Basis for this page: sources/jev/docs/cookbooks/autoformat.md; local copies of the official example input and cache: sources/jev/extra/c2-autoformat-build-memo.txt, sources/jev/extra/c2-autoformat-json-cache.json. The numbers above come from cross-checking the public example against the local cache (the cache contains recorded answers for two line-joining runs and one classification run), not from a new live performance test initiated for this lesson.
Next lesson preview
The next lesson covers Natural-language ordering: converting to a structured shopping cart, continuing the practice of breaking business problems into explicit judgments and then letting the program handle the results. You can also go back to Value extraction to contrast "identifying information" with "recovering structure."