Skip to content

feat: default web_search to approximate location (#3180)#3195

Open
lrg913427-dot wants to merge 1 commit intoopenai:mainfrom
lrg913427-dot:feat/web-search-default-location
Open

feat: default web_search to approximate location (#3180)#3195
lrg913427-dot wants to merge 1 commit intoopenai:mainfrom
lrg913427-dot:feat/web-search-default-location

Conversation

@lrg913427-dot
Copy link
Copy Markdown

Closes #3180.

When web_search tools are used without specifying user_location, the server defaults to injecting country: "US" into the system prompt. This aligns SDK behavior with the OpenAI Playground by injecting user_location: {type: approximate} as the default, preventing hidden US geolocation assumptions for non-US developers.

Changes

  • src/openai/lib/_tools.py: Added _apply_web_search_default_location_tools() helper that injects default user_location into web_search tools
  • src/openai/resources/responses/responses.py: Applied preprocessing to all 6 tool parameter locations
  • tests/lib/test_tools.py: 11 unit tests covering all edge cases

Behavior

  • Tools without type: web_search* are unaffected
  • Web search tools with existing user_location are not overridden
  • Covers all 4 web_search type variants

@lrg913427-dot lrg913427-dot requested a review from a team as a code owner May 2, 2026 18:11
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07a9fba949

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/openai/lib/_tools.py
changed = True
result.append(tool)

return result if changed else tools
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Return collected tools to avoid exhausting iterators

If tools is a one-shot iterable (e.g., generator/iterator), this function consumes it in the for loop and then returns the original iterable when changed is false. In that case the caller (all responses.* create/stream paths now using this helper) receives an already-exhausted iterable, so no tools are sent at all. This regression appears whenever users pass non-reiterable Iterable[ToolParam] values that either contain no web-search tool or only web-search tools that already have user_location.

Useful? React with 👍 / 👎.

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.

Default web search to type="approximate"

1 participant