0Pricing
Claude Architect · บทเรียน

ตัวอย่างแบ่งตามหมวดหมู่

แสดงตัวอย่างสิ่งที่ต้องรายงานและสิ่งที่ต้องละเว้น

ตัวอย่างแบ่งตามหมวดหมู่ เป็นบทเรียน Claude Architect ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Claude Architect และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

Why Categorical Examples Matter

When you give Claude a job that has a fuzzy boundary, vague instructions like "be more precise" rarely work. The model can't read your mind about where the line sits.

The reliable fix is categorical examples: a small set of 2-4 few-shot examples that show concrete cases of what to report and what to ignore. The model generalizes from these examples to new, unseen inputs — it does not merely repeat them.

This lesson shows how to build those examples for a classic architect task: deciding what is worth flagging and what is noise.

Explicit Criteria Beat Vague Adjectives

Before you even reach for examples, state an explicit criterion. Explicit rules consistently beat vague adjectives.

  • Vague: "Review the code carefully."
  • Explicit: "Flag a comment only when it contradicts the code it describes."

The explicit version draws a sharp line. Categorical examples then make that line unmistakable by pinning it to concrete cases on each side.

system = (
    "You review code comments. "
    "Flag a comment ONLY when it contradicts the code it describes. "
    "Ignore style, tone, and outdated-but-harmless notes."
)

The Shape of a Categorical Example Set

A good set has examples on both sides of the boundary, each with a one-line reason. Two REPORT cases and two IGNORE cases is enough for most ambiguities — 2-4 targeted examples is the sweet spot.

Each example carries three parts:

  • the input (the thing being judged)
  • the verdict (report / ignore)
  • a short reason tied to your criterion

The reason is what lets the model generalize correctly instead of pattern-matching on surface features.

Worked Example: Report vs Ignore

Here is a categorical example block for the comment-review task. Notice the symmetry: contradictions are reported; harmless mismatches are ignored.

EXAMPLES = """
<example verdict="REPORT">
  code: return price * 1.2
  comment: # applies 10% tax
  reason: comment says 10% but code applies 20% (contradiction)
</example>
<example verdict="IGNORE">
  code: timeout = 30  # seconds
  comment: # seconds
  reason: accurate; matches the code
</example>
<example verdict="IGNORE">
  code: # TODO: refactor later
  comment: # TODO: refactor later
  reason: stylistic note, not a contradiction
</example>
<example verdict="REPORT">
  code: if user.is_admin: deny()
  comment: # allow admins
  reason: comment says allow but code denies (contradiction)
</example>
"""

Generalization, Not Memorization

The power of categorical examples is that the model generalizes. It does not need an example for every possible input.

From the four cases above, Claude learns the rule "flag semantic contradictions, ignore harmless mismatches" and applies it to a brand-new comment it has never seen, such as a docstring that claims a function returns a list when it returns a dict.

This is why few-shot examples are ideal for consistency, edge cases, output format, and reducing hallucination.

Pin the Edges of the Boundary

The most valuable examples sit right at the boundary, where the decision is genuinely hard. A near-miss IGNORE next to a near-hit REPORT teaches far more than two obvious cases.

For a research agent deciding which statistics to surface, you might contrast a stale figure with a current one — and note that dates often resolve apparent contradictions rather than one number simply being wrong.

EXAMPLES = """
<example verdict="REPORT">
  fact: "Revenue was $4.1B in FY2024" (source dated 2025-02)
  reason: current, sourced, on-topic -> surface it
</example>
<example verdict="IGNORE">
  fact: "Revenue was $3.2B" (source dated 2019, no fiscal year)
  reason: stale and undated for our scope -> drop, do not treat as a conflict
</example>
"""

Examples Drive Structured Output Too

Categorical examples pair naturally with structured output. When the verdict must be machine-readable, force a tool call so the result is valid JSON every time.

Use tool_choice of type "any" to guarantee the model calls some tool (guaranteeing structured output), or force one specific tool by name. A JSON Schema then eliminates syntax errors and enforces required fields.

tools = [{
    "name": "record_finding",
    "description": "Record a review verdict for one item.",
    "input_schema": {
        "type": "object",
        "properties": {
            "verdict": {"enum": ["report", "ignore"]},
            "reason": {"type": "string"}
        },
        "required": ["verdict", "reason"]
    }
}]

resp = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=512,
    tools=tools,
    tool_choice={"type": "any"},
    system=system,
    messages=[{"role": "user", "content": EXAMPLES + new_item}],
)

Only Require Fields That Always Exist

A subtle trap: in your finding schema, mark a field required only if it is always present. If you require a field that may be absent — say a line_number for findings that aren't line-specific — the model will fabricate a value to satisfy the schema.

For categories that may grow, use an enum plus an "other" value and a free-text detail field. That keeps the output structured while staying extensible.

"category": {"enum": ["contradiction", "security", "other"]},
"category_detail": {"type": "string"}  # filled when category == other
# line_number is NOT required: many findings are file-level

When Examples Are the Wrong Tool

Categorical examples sharpen a judgment boundary. They do not invent missing information.

If the model returns an empty or wrong result because the needed fact is simply absent from the source, more examples won't help — and neither will retry-with-feedback. Retry fixes format, structural, and arithmetic errors, not absent data.

Distinguish a genuine empty result ("no matches found") from an access failure (the source couldn't be read). Treat them differently in your recovery logic.

Categorical Examples in CLAUDE.md and Reviews

Bake your report/ignore policy where the work happens. For a CI review job, put the examples in project-level CLAUDE.md (shared via VCS) so every run and every teammate inherits the same boundary.

In CI, run the review in an isolated session (less biased than the generation context) with -p for non-interactive output. Explicit criteria plus categorical examples are exactly how you minimize false positives.

## Review policy (categorical)
REPORT: a comment that contradicts the code it describes.
IGNORE: style nits, tone, outdated-but-harmless TODOs.

Example REPORT -> `# 10% tax` over `price * 1.2`
Example IGNORE -> `timeout = 30  # seconds` (accurate)

Putting It Together

The full recipe for a clean report/ignore decision:

  • Write one explicit criterion for the boundary.
  • Add 2-4 categorical examples split across both sides, each with a reason.
  • Pin examples at the hard edges, not the obvious cases.
  • Force structured output with a tool; require only ever-present fields.
  • Remember: examples shape judgment, not missing data.

Do this and Claude generalizes your intent reliably across inputs it has never seen.

Quick Check

A review agent flags too many harmless comments as problems. You want it to report only genuine contradictions. Which change will most reliably tighten the boundary?

Recap

Key takeaways:

  • Explicit criteria + categorical examples beat vague adjectives for fuzzy boundaries.
  • Use 2-4 examples split across report and ignore, each with a reason; the model generalizes, it doesn't just repeat.
  • Pin examples at the hard edges; remember dates often resolve apparent contradictions.
  • Pair with structured output (tool_choice "any" + JSON Schema); require only ever-present fields, use enum+"other" for extensibility.
  • Examples sharpen judgment, not missing data — absent facts need a different fix, and retry only repairs format/arithmetic errors.

คำถามที่พบบ่อย

บทเรียน “ตัวอย่างแบ่งตามหมวดหมู่” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ตัวอย่างแบ่งตามหมวดหมู่” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Claude Architect ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ตัวอย่างแบ่งตามหมวดหมู่”

แสดงตัวอย่างสิ่งที่ต้องรายงานและสิ่งที่ต้องละเว้น คุณปฏิบัติ Claude Architect ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Claude Architect หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Claude Architect บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน

บทเรียน “ตัวอย่างแบ่งตามหมวดหมู่” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Claude Architect นี้ได้ไหม

ได้ บทเรียน Claude Architect ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. เกณฑ์ที่ชัดเจนเทียบกับคำสั่งกำกวม
  2. ตัวอย่างแบ่งตามหมวดหมู่
  3. เกณฑ์ระดับความรุนแรงพร้อมตัวอย่าง
  4. การลดผลบวกเท็จ
← กลับไปที่ Claude Architect