feat: cleanse search response to strip UI-specific fields#71
Merged
steve-calvert-glean merged 2 commits intomainfrom Apr 3, 2026
Merged
feat: cleanse search response to strip UI-specific fields#71steve-calvert-glean merged 2 commits intomainfrom
steve-calvert-glean merged 2 commits intomainfrom
Conversation
Strip the SDK's bloated SearchResponse down to only the fields relevant to programmatic consumers, aligning with the RFC for POST /api/search. This is a stopgap until the new API ships. - Add allowlist-based response cleansing (internal/output/cleanse.go) - Filter out empty structured results that have no document or title - Sub-filter author to only name and email - Add --raw flag to bypass cleansing for full SDK response - Warn on stderr when --fields requests a cleansed-away field - Extend WriteNDJSON to handle cleansed map[string]any responses Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
chris-freeman-glean
approved these changes
Apr 3, 2026
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SearchResponsedown to only RFC-aligned fields relevant to programmatic consumers (stopgap untilPOST /api/searchships)--rawflag to bypass cleansing and get the full SDK response--fieldsrequests a field that was removed by cleansingDetails
The current search response includes 17+ top-level fields and deeply nested UI-specific data (tracking tokens, session info, structured results, generated QnA, experiment IDs, facet rendering config, etc.). This change uses an allowlist approach to keep only:
Response level:
results,cursor,hasMoreResults,requestIDResult level:
title,url,snippets,documentDocument level:
title,url,datasource,docType,metadata(filtered to author/times)Author level:
name,emailEmpty structured results (knowledge cards with no document/title) are filtered out.
Deletion path
When
POST /api/searchships: deletecleanse.go+cleanse_test.go, remove--rawflag fromsearch.go, removemap[string]anybranch fromformatter.go.Test plan
go test ./...— 365 tests passgolangci-lint run— no issuesglean search "query"— cleansed output verifiedglean search --raw "query"— full SDK response verifiedglean search --output ndjson "query"— one cleansed result per lineglean search --fields "results.trackingToken,results.title" "query"— warning on stderr, allowed fields shownglean search --fields "results.title,results.document.url" "query"— no warning, projection works🤖 Generated with Claude Code