spring-projects/spring-ai · warning
No sessionId provided in ToolSearchRequest, returning empty…
Error message
No sessionId provided in ToolSearchRequest, returning empty results
What it means
RegexToolIndex.search requires a sessionId to select the per-session regex index. When ToolSearchRequest.sessionId is null or blank, it logs this warning and returns an empty ToolSearchResponse, since no session index exists to search. Mirrors the LuceneToolIndex behavior for session-scoped tool indexes.
Solutions
- Provide a non-blank sessionId on the ToolSearchRequest.
- Ensure sessionId is captured and forwarded from the conversation/session context to every tool search call.
- Log/validate the request in the caller before invoking search to catch blank session IDs early.
- Recognize the empty response as 'rejected due to missing sessionId', not 'no tools matched'.
Example fix
// before
var resp = regexToolIndex.search(new ToolSearchRequest("find flight tools", 5, null, null));
// after
var resp = regexToolIndex.search(new ToolSearchRequest("find flight tools", 5, "session-42", null)); Defensive patterns
Strategy: validation
Validate before calling
if (request.sessionId() == null || request.sessionId().isBlank()) {
throw new IllegalArgumentException("sessionId is required for RegexToolIndex.search");
} Prevention
- Validate ToolSearchRequest fields before calling search.
- Propagate session IDs consistently from the agent framework.
- Cover session-scoped search in integration tests.
- Do not reuse request builders designed for sessionless indexes.
When it happens
Trigger: Calling search on a RegexToolIndex with a ToolSearchRequest whose sessionId is null or empty/blank — typically a manually constructed request omitting sessionId.
Common situations: Tests or custom delegates building ToolSearchRequest without a session; callers switching from non-session-scoped search to RegexToolIndex without adapting request construction; session ID lost between layers of the application.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
- No sessionId provided in ToolSearchRequest, returning empty…
- No tool call requested by the chat model
- Skipping add for session
- Unknown…
- VectorToolIndex does not support categoryFilter
AI-assisted analysis of spring-projects/spring-ai@98a7beda4f (2026-09-11).
Data as JSON: /api/errors/339bca6bbf7a65b9.
Report an issue: GitHub.
Appendix: source
Thrown at spring-ai-tool-search-tool/src/main/java/org/springframework/ai/tool/toolsearch/index/regex/RegexToolIndex.java:121
}
@Override
public void indexTools(String sessionId, List<ToolReference> toolReferences) {
SessionIndex sessionIndex = getOrCreateSessionIndex(sessionId);
for (ToolReference ref : toolReferences) {
String id = String.valueOf(this.counter.getAndIncrement());
sessionIndex.addTool(new ToolEntry(id, ref.toolName(), ref.summary()));
}
if (logger.isDebugEnabled()) {
logger.debug("Added " + toolReferences.size() + " tools to session '" + sessionId + "'");
}
}
@Override
public ToolSearchResponse search(ToolSearchRequest toolSearchRequest) {
String sessionId = toolSearchRequest.sessionId();
if (sessionId == null || sessionId.isBlank()) {
logger.warn("No sessionId provided in ToolSearchRequest, returning empty results");
return ToolSearchResponse.builder().build();
}
SessionIndex sessionIndex = this.sessionIndexes.get(sessionId);
if (sessionIndex == null) {
logger.debug("No index found for session: " + sessionId);
return ToolSearchResponse.builder().build();
}
String query = toolSearchRequest.query();
int maxResults = toolSearchRequest.maxResults() != null ? toolSearchRequest.maxResults() : DEFAULT_MAX_RESULTS;
// Convert natural language query to regex pattern
String regexPattern = convertQueryToRegexPattern(query);
if (logger.isDebugEnabled()) {
logger.debug("Converted query '" + query + "' to regex pattern '" + regexPattern + "'");
}
View on GitHub (pinned to 98a7beda4f)