Skip to content

feat(hints): add label field to StructuredHint#217

Merged
HumanBean17 merged 2 commits into
masterfrom
feat/hints-structured-label
May 24, 2026
Merged

feat(hints): add label field to StructuredHint#217
HumanBean17 merged 2 commits into
masterfrom
feat/hints-structured-label

Conversation

@HumanBean17

Copy link
Copy Markdown
Owner

Summary

  • Add label: str field to _StructuredHint (internal NamedTuple) and StructuredHint (public Pydantic model)
  • 37 named LABEL_* constants derived from existing TPL_* template prefixes (e.g. "routes via members", "implementors", "handler")
  • Every _StructuredHint(...) constructor now includes a label
  • _to_structured_hints passes label through to the public API

Motivation

String hints encode a semantic name before the colon ("routes via members: neighbors(...)"), but hints_structured had no equivalent — LLM agents had to infer hint purpose from args alone. A label field provides a stable, human-readable category tag.

Relationship to #211 (reason field)

label and reason are complementary: label is what (1–4 word semantic name), reason is why (full advisory text). See the analysis in #216.

Scope

  • mcp_hints.py — add label field to _StructuredHint, add LABEL_* constants, update all constructors
  • mcp_v2.py — add label field to StructuredHint, update _to_structured_hints
  • propose/HINTS-STRUCTURED-LABEL.md — propose document

No reindex required — output-only change.

Validation

.venv/bin/ruff check mcp_hints.py mcp_v2.py  # passed
.venv/bin/python -m pytest tests/test_mcp_hints.py -v  # 215 passed, 1 SSL-infrastructure failure unrelated to changes

Closes #216

🤖 Generated with Claude Code

Add a short semantic label (e.g. "routes via members", "implementors",
"handler") to every structured hint so LLM agents can triage hints
without parsing args. 37 named LABEL_* constants derived from existing
TPL_* template prefixes.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@HumanBean17 HumanBean17 left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: label field for StructuredHint

Reviewed the diff across all 3 files (mcp_hints.py, mcp_v2.py, propose/HINTS-STRUCTURED-LABEL.md).

Correctness

All label values match their corresponding string template prefixes exactly (the text before the first : in TPL_* constants). For colon-less advisory templates, the assigned labels are sensible short descriptions (e.g., "high fanout", "fuzzy strategy", "weak results").

Every _StructuredHint(...) constructor (47 total) now includes a label argument. No constructors were missed. Verified programmatically by scanning all _StructuredHint( calls and confirming LABEL_ appears in each constructor body.

Completeness

Three LABEL_* constants are defined but never used in any _StructuredHint constructor:

  • LABEL_ROLE_FILTER_FALLBACK ("role filter fallback") -- pairs with TPL_NEIGHBORS_CALLS_ROLE_FILTER_OTHER_FALLBACK
  • LABEL_ROLE_COLLISION ("role collision") -- pairs with TPL_NEIGHBORS_CALLS_NODEFILTER_ROLE_COLLISION
  • LABEL_HAS_UNRESOLVED ("has unresolved") -- pairs with TPL_NEIGHBORS_CALLS_HAS_UNRESOLVED

These correspond to string-only hints in neighbors_calls_meta_hints and neighbors_calls_fanout_hints which currently have no structured hint counterparts. This is not a bug -- the string hints fire in those functions but no _StructuredHint is emitted alongside them. The unused constants are harmless (dead code, not incorrect), but worth noting for a follow-up if structured counterparts are planned.

Consistency

Similar hints consistently get the same label regardless of context. For example:

  • "declaring method" is used for all route/client/producer declaring-method lookups (N5, N6, describe route/client/producer)
  • "HTTP targets" is used consistently for HTTP_CALLS outbound follow-ups
  • "handler" is used consistently for EXPOSES inbound lookups

StructuredHint field ordering

StructuredHint in mcp_v2.py: label is placed before tool, which puts the human-readable identifier first in JSON output. Good choice -- LLM consumers see the semantic name before the technical details.

_StructuredHint NamedTuple: label is last with default "", which is correct and required by Python's NamedTuple (defaulted fields must follow non-defaulted fields).

Description update

MCP_HINTS_STRUCTURED_FIELD_DESCRIPTION is updated to mention label before tool, consistent with the new field order.

Propose alignment

The propose document lists tests/test_mcp_hints.py -- assert on label values in scope, but the PR includes no test changes. Existing tests still pass (216 passed, 2 skipped) because label="" is the default on _StructuredHint. No test asserts that labels are present or correct. This is a minor gap -- explicit label assertions would strengthen coverage.

Validation

  • ruff check mcp_hints.py mcp_v2.py -- all checks passed
  • pytest tests/test_mcp_hints.py -- 216 passed, 2 skipped

Verdict: LGTM. The implementation is correct, complete (all constructors labeled), and consistent. The three unused label constants are minor dead code. The missing test assertions for labels are a gap noted in the propose doc but not blocking.

- Add label parameter to _assert_structured_hint helper
- Assert all structured hints have non-empty labels in parity + round-trip tests
- Add test_structured_hint_label_values with 13 specific label checks
- Remove 3 unused LABEL_* constants (role filter fallback, role collision,
  has unresolved) — will be added when structured counterparts are built

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@HumanBean17 HumanBean17 merged commit 1c1d7d5 into master May 24, 2026
1 check passed
@HumanBean17 HumanBean17 deleted the feat/hints-structured-label branch May 24, 2026 12:08
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.

Add label field to StructuredHint

1 participant