Skip to content

polish(estimate_paragraph_for_page): closes #143 #145 #146 - #156

Open
kiki830621 wants to merge 1 commit into
mainfrom
polish/estimate-paragraph-bundle-c
Open

polish(estimate_paragraph_for_page): closes #143 #145 #146#156
kiki830621 wants to merge 1 commit into
mainfrom
polish/estimate-paragraph-bundle-c

Conversation

@kiki830621

Copy link
Copy Markdown
Member

Summary

Bundle C from PR #114 6-AI verify follow-up. Three orthogonal polish items in a single tool / code path:

#143 (P2) — Confidence label calibration

Pre-fix: caller-supplied chars_per_page downgraded confidence to "low" (semantic inversion — caller calibration is ground truth, not heuristic noise).

Post-fix ladder (confidence + new confidence_reason field):

confidence confidence_reason trigger
high caller_provided_chars_per_page caller calibration trusted
medium default_heuristic_long_doc paragraph_count ≥ 10
low default_heuristic_short_doc short docs
low page_beyond_estimated_document out-of-range page
low empty_document 0 paragraphs

Threshold tightened from 3 → 10 paragraphs (3-paragraph docs are below per-paragraph noise floor).

#145 (P3) — Error format unification

Three invalid_parameter paths now return structured JSON via new estimateValidationError helper:

{
  "error": "invalid_parameter",
  "tool": "estimate_paragraph_for_page",
  "field": "page" | "chars_per_page" | "context_paragraphs",
  "reason": "must be 1..100000" | ...,
  "received": <int>
}

empty_document path also normalized — now returns method / layout_basis / confidence / confidence_reason so callers parse uniformly without branching on error key first.

received echo also satisfies #129 within this tool's scope.

#146 (P3) — Schema description polish

  • Confidence ladder enumerated in schema description
  • Default chars_per_page derivation formula documented (≈1189 for A4 / ≈1134 for Letter / 3000-3500 for English IEEE)
  • JSON error format documented
  • Per-arg descriptions added clamp ranges

Tests

7 → 12 in Issue89EstimateParagraphForPageTests:

Full suite: 266 → 271, 0 failures, 9 pre-existing skips.

Backward compat

Breaking schema change for callers parsing the plain-text Error: estimate_paragraph_for_page: ... strings — they now get JSON. estimate_paragraph_for_page was added in #114 (just merged), so this is essentially shipping the corrected v1 contract before any external caller adopts the v0 plain-text format.

Existing valid callers (page within range, chars_per_page provided as positive int, etc.) get the same response shape with one additive new field (confidence_reason).

Refs #143 #145 #146

Bundle C from PR #114 6-AI verify follow-up. Three orthogonal polish
items in a single tool, single code path:

#143 (P2) — Confidence label calibration
  Pre-fix: caller-supplied chars_per_page DOWNGRADED confidence to "low"
  because layoutBasis switched to "caller_chars_per_page" and the medium
  predicate required "section_properties". Inverted semantics — caller
  calibration is ground truth, not heuristic noise.

  Post-fix ladder (confidence + new confidence_reason field):
    high   / caller_provided_chars_per_page    — caller calibration trusted
    medium / default_heuristic_long_doc        — paragraph_count >= 10
    low    / default_heuristic_short_doc       — short docs
    low    / page_beyond_estimated_document    — out-of-range page
    low    / empty_document                    — 0 paragraphs

  Threshold tightened from 3 to 10 paragraphs for medium per verify
  P2 (3-paragraph docs are below per-paragraph noise floor).

#145 (P3) — Error format unification
  Three calibration errors previously returned plain-text
  "Error: estimate_paragraph_for_page: ..." while WordError went through
  MCP runtime as structured. Caller parser had to fork.

  Post-fix: all 3 invalid-parameter paths return structured JSON via new
  estimateValidationError helper:
    {
      "error": "invalid_parameter",
      "tool": "estimate_paragraph_for_page",
      "field": "page" | "chars_per_page" | "context_paragraphs",
      "reason": "must be 1..100000" | ...,
      "received": <int>
    }

  empty_document path also normalized: now returns method / layout_basis /
  confidence / confidence_reason fields so callers can parse uniformly
  without branching on error key first.

  echo received value also satisfies #129 within this tool's scope.

#146 (P3) — Schema description polish
  Schema description now enumerates the confidence ladder, documents the
  default chars_per_page derivation formula (charsPerLine * linesPerPage,
  ≈1189 for A4 / ≈1134 for Letter / 3000-3500 for English IEEE), and lists
  the JSON error format. Per-arg descriptions added clamp ranges
  (page 1..100000, chars_per_page 1..200000, context_paragraphs 0..1024).

Tests: 7 → 12 in Issue89EstimateParagraphForPageTests
  - existing 7 updated to assert structured JSON instead of plain-text Error:
  - testCallerProvidedCharsPerPageGivesHighConfidence (P0 for #143 fix)
  - testLongDocumentDefaultHeuristicGivesMediumConfidence
  - testShortDocumentDefaultHeuristicGivesLowConfidence
  - testBeyondDocumentRequestKeepsLowConfidence
  - testEmptyDocumentReturnsStructuredErrorWithFullSchema (#145)

Full suite: 266 → 271, 0 failures, 9 pre-existing skips.

Refs #143 #145 #146
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant