사례 사실 블록 및 출력 잘라내기
요약 외부에 사실을 고정하고 장황한 도구 결과를 줄입니다
사례 사실 블록 및 출력 잘라내기은(는) CoddyKit의 무료 Claude Architect 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Claude Architect 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
The Long-Conversation Problem
In a long agentic conversation, the full message history grows past what's comfortable to keep in context. The common fix is progressive summarization: compress older turns into a running summary so the window stays manageable.
But summarization has a quiet failure mode. It's great at preserving the gist of a conversation and terrible at preserving exact values. As you compress, the precise things a model needs to act correctly start to blur.
What Summarization Destroys
Progressive summarization makes numbers, percentages, and dates vague. A turn that said "order #88231 shipped 2026-03-14, refund of $412.50 approved" can degrade into "the customer's order shipped recently and a refund was approved."
That's fine for narrative flow, but catastrophic for a tool-calling agent that must pass order_id=88231 or reason about a $412.50 threshold. The model can't recover a value the summary already erased.
The Fix: A Case-Facts Block
The architectural pattern is to pull transactional facts into a separate "case facts" block kept verbatim, outside the summary. The summary handles the conversational narrative; the case-facts block holds the exact, load-bearing values.
Crucially, this block is never summarized or compressed. When you compact older turns, the case-facts block passes through unchanged. The summary can be lossy; the facts cannot.
What Belongs in Case-Facts
Put anything exact and consequential in the case-facts block:
- IDs: order numbers, customer IDs, ticket numbers, SKUs
- Amounts and thresholds: refund totals, balances, limits
- Dates and timestamps: ship dates, deadlines, SLA windows
- Verified identity state: e.g. "customer identity confirmed via get_customer"
Leave chit-chat, rephrasings, and explanatory prose in the summary. The test: would a wrong or vague value here cause a wrong action? If yes, it's a case-fact.
Structuring the Block
Keep the case-facts block as terse, structured key/value lines — easy for the model to scan and copy verbatim into tool inputs. Inject it into the system prompt or as a pinned context block that rides along every turn.
CASE_FACTS = """
<case_facts>
customer_id: CUST-77421 (identity: VERIFIED via get_customer)
order_id: 88231
ship_date: 2026-03-14
refund_requested: 412.50 USD
refund_policy_threshold: 500.00 USD
</case_facts>
"""
system = (
"You are a support agent. The values in <case_facts> are "
"authoritative and exact. Always copy IDs and amounts from "
"<case_facts> verbatim; never reconstruct them from the summary.\n\n"
+ CASE_FACTS
)Summary + Facts Working Together
The two pieces are complementary. On each turn you send: a compressed summary of older narrative, the verbatim case-facts block, and the recent raw turns. Remember the model keeps no state — you resend this whole assembly every request.
The summary keeps the window small; the case-facts block guarantees the exact values survive. Compress aggressively in the summary, knowing the facts that matter are safe elsewhere.
def build_messages(summary, recent_turns):
# case_facts lives in `system`; summary + recent turns in messages
return [
{"role": "user",
"content": f"<conversation_summary>{summary}</conversation_summary>"},
*recent_turns, # last few raw turns, uncompressed
]
resp = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
system=system, # contains the verbatim CASE_FACTS block
messages=build_messages(summary, recent_turns),
tools=tools,
)Lost in the Middle
There's a second reason placement matters. Models exhibit a lost-in-the-middle effect: they attend more strongly to the start and end of the context than to the middle.
So a critical fact buried in the middle of a huge tool dump or a long summary is the most likely thing to be overlooked. Position your case-facts block where attention is strongest — early in the system prompt or pinned near the end of the input.
The Other Half: Verbose Tool Output
Case-facts solve retention. The second discipline is controlling what enters the window in the first place. Tools — APIs, database queries, file reads — often return huge, deeply nested JSON payloads, most of which is irrelevant to the decision at hand.
Appending that raw blob to history bloats the window, pushes important content into the lost-in-the-middle zone, and dilutes the model's attention. The rule: trim verbose tool output to the relevant fields before the model sees it.
Trimming in Code
Do the trimming deterministically in your own code, between getting the raw result and appending it to the message history. Extract only the fields the model actually needs to reason or to fill the next tool call.
raw = lookup_order(order_id=88231)
# raw has 60+ fields: internal flags, audit log, warehouse meta, etc.
trimmed = {
"order_id": raw["order_id"],
"status": raw["status"],
"total": raw["total"],
"ship_date": raw["fulfillment"]["ship_date"],
}
messages.append({
"role": "user",
"content": [{
"type": "tool_result",
"tool_use_id": tool_use_id,
"content": json.dumps(trimmed),
}],
})Trimming with a PostToolUse Hook
You can also enforce trimming with a PostToolUse hook, which intercepts a tool result before the model sees it. This makes trimming deterministic and centralized rather than relying on each tool's implementation to behave.
The hook is the right home for a strict, always-applied projection of fields — the same deterministic-enforcement logic you'd use for any policy that must run 100% of the time, not ~90% of the time as a prompt would.
# PostToolUse hook: keep only whitelisted fields per tool
KEEP = {
"lookup_order": ["order_id", "status", "total", "ship_date"],
}
def on_post_tool_use(tool_name, result):
keys = KEEP.get(tool_name)
if not keys:
return result
return {k: result[k] for k in keys if k in result}Trim, but Don't Lose Provenance
Trim for relevance — not so hard that you discard what you'll later need to act or to cite. If a value is going to drive a tool call or a customer-facing claim, promote it into the case-facts block instead of dropping it.
One clean division of labor: trim tool output going into the running history, and pin the exact values that must survive into the verbatim case-facts block. Lossy where it's safe, verbatim where it's not.
Quick Check
A support agent runs long multi-turn sessions. To stay in budget, older turns are progressively summarized. Testers report it sometimes refunds the wrong amount or passes a stale order number after the conversation has run a while. What's the best fix?
Recap
Key takeaways:
- Progressive summarization blurs exact values — numbers, percentages, and dates go vague.
- Pin transactional facts in a verbatim case-facts block outside the summary; the summary may be lossy, the facts must not be.
- Lost-in-the-middle: models attend most to the start and end — place critical facts there, not buried mid-context.
- Trim verbose tool output to relevant fields before appending to history; a PostToolUse hook makes this deterministic.
- Division of labor: trim what flows into history, pin what must survive verbatim. Lossy where safe, exact where it counts.
자주 묻는 질문
“사례 사실 블록 및 출력 잘라내기” 강의는 무료인가요?
네 — “사례 사실 블록 및 출력 잘라내기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Claude Architect 강의 전체를 잠금 해제할 수 있습니다. Claude Architect 강의에는 총 4개의 강의가 포함되어 있습니다.
“사례 사실 블록 및 출력 잘라내기”에서 뭘 배우나요?
요약 외부에 사실을 고정하고 장황한 도구 결과를 줄입니다 브라우저에서 직접 실행하는 실습 코드로 Claude Architect을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Claude Architect을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Claude Architect은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.
“사례 사실 블록 및 출력 잘라내기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Claude Architect 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Claude Architect 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 전체 이력이 필요합니다
- 점진적 요약의 위험
- 중간 누락 효과
- 사례 사실 블록 및 출력 잘라내기