Skip to content

java: enforce non-blank @CopilotToolParam description at compile time#1980

Open
rinceyuan wants to merge 1 commit into
github:mainfrom
rinceyuan:feat/java-blank-param-validation
Open

java: enforce non-blank @CopilotToolParam description at compile time#1980
rinceyuan wants to merge 1 commit into
github:mainfrom
rinceyuan:feat/java-blank-param-validation

Conversation

@rinceyuan

Copy link
Copy Markdown
Contributor

Closes #1836

Summary

Adds compile-time validation in CopilotToolProcessor to reject @CopilotToolParam annotations with blank value() (description). Without a meaningful description, the LLM cannot reliably select and invoke tools.

Changes

CopilotToolProcessor.java

  • Added blank-description check after the single-record wrapper validation block
  • Checks paramAnnotation.value().isBlank() (catches both empty and whitespace-only)
  • Single-record wrapper parameters are exempt (as specified in the issue)
  • Error message identifies the parameter name, enclosing method, and class

CopilotToolProcessorTest.java (5 new tests)

  1. Blank value@CopilotToolParam("") produces compile error
  2. Whitespace-only value@CopilotToolParam(" ") produces compile error
  3. Valid value@CopilotToolParam("Search query") compiles without error
  4. No annotation — unannotated parameter compiles without error
  5. Record wrapper exemption@CopilotToolParam on single-record wrapper is exempt

Error message example

error: @CopilotToolParam on parameter 'query' in 'BlankDescTools.searchItems' has a blank value (description).
Descriptions are required so the LLM can correctly select and invoke the tool

Testing

  • mvn test -Dtest=CopilotToolProcessorTest — 39 tests pass (0 failures)
  • All existing tests pass with no regressions
  • Local JDK is 17; CI will run the full mvn verify with JDK 25+

Closes github#1836

Add compile-time validation in CopilotToolProcessor to reject
@CopilotToolParam annotations with blank value (description).

- Blank or whitespace-only descriptions now produce a compile error
- Single-record wrapper parameters are exempt (they delegate to
  record component annotations)
- Error message identifies parameter name, method, and class
- 5 new tests covering blank, whitespace, valid, unannotated, and
  record-wrapper cases
@rinceyuan rinceyuan requested a review from a team as a code owner July 14, 2026 08:30
@rinceyuan

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree company=Microsoft

@rinceyuan

Copy link
Copy Markdown
Contributor Author

@edburns Hi! This implements #1836 — compile-time validation for blank @CopilotToolParam descriptions in the annotation processor. 5 new tests, all passing. Would appreciate your review. Thanks!

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.

[Java] @CopilotTool ergonomics: Enforce non-blank @Param description at compile time

1 participant