Search API Practices

The query you send is not the query that runs

The query you send is not the query that runs

You write a query string, wrap it in a request, and assume the engine searched for what you typed. Often it did not. Between your string and the executed search sit a normaliser, several default switches you never set, and a market selection that is not a translation layer. Each of them changes the answer, and none of them raises an error.

The response does report one of these changes, in a field named query whose documented description is the normalized query taken from your request (checked 2026-11-27, /docs/google_web_search). That field is your receipt. Everything else has to be understood before it happens, because the body will not tell you.

Normalisation happens first, and silently

Before any search runs, the string is normalised. Whitespace collapses, casing is regularised, and whatever else the platform considers presentation gets settled. What comes back in query is the result of that pass, not your original bytes.

The practical consequence is that two requests which differ only in spacing or capitalisation can be one request, and a cache keyed on your raw string will hold two entries for one search. It also means a log line that stores only what you sent cannot answer the question "what did we actually ask", which is the question you will have in an incident review.

Store both. The sent string and the echoed query are two facts, and their difference is a measurement of how much of your input survived.

Your typo may have been corrected for you

By default the engine applies spelling correction. A query containing a misspelling is answered as though the misspelling were not there, and the response carries no flag announcing the substitution.

The documented switch for this is nfpr. Passing "1" sends your string through untouched, bypassing Google's spelling correction, while "0" leaves the default behaviour in place (checked 2026-11-27, /docs/google_web_search).

That switch is a policy decision, not a nicety. A product that answers "how do I spell X" must set nfpr to "1", or it will confidently answer a question the user did not ask. A product searching an internal catalogue of proper nouns wants it set too, because a corrected brand name finds the wrong product. A product answering general research questions is usually better off leaving the default in place.

Near-duplicates are dropped by default

The filter switch decides whether results Google considers similar to one another are shown. Passing "0" also shows the results Google omits as similar to others, while "1" is the default (checked 2026-11-27, /docs/google_web_search).

So the default answer to "how many distinct pages mention this" is already a deduplicated answer produced by a rule you did not write. If your pipeline counts results, that count reflects Google's similarity judgement rather than the number of pages in existence. Turning the filter off does not give you the second number either; it gives you a different list.

Two more switches sit in the same family. pws set to "0" asks Google not to personalise results, and complete set to "0" turns off autocomplete for the request (checked 2026-11-27, /docs/google_web_search). Both default to "1". Neither changes your visible query string, and both change what comes back.

Filters are passed through, and a malformed one is refused

tbs carries Google's own search tools unchanged, and it is where time filters and verbatim mode live. The documented forms are readable: qdr:m with h, d, w, y in place of m for the past hour, day, week or year, with an optional number so qdr:m6 means six months; a date range as cdr:1,cd_min:1/1/2026,cd_max:3/31/2026; sbd:1 to sort by date; li:1 for verbatim. Pairs are joined with commas (checked 2026-11-27, /docs/google_web_search).

This is one of the rare places where the platform refuses rather than guesses: a value that is not name-colon-value pairs is refused with status 1000. That is a good failure. What it protects you from is the worse case in the neighbouring parameter, where a malformed value is dropped and the search runs with the filter silently absent.

A time filter is the highest-risk of these, because its absence looks like a data problem rather than a parameter problem. A pipeline that believes it is searching the last seven days and is actually searching everything will produce results that look stale for reasons nobody attributes to the request.

The market is not a translation

Setting gl and hl does not translate your query. It selects a different index, in a different language, at a different address, and returns what that index has. The defaults are us and en, so a request that omits both is a US-English request rather than a neutral one (checked 2026-11-27, /docs/google_web_search).

The mistake worth naming is assuming equivalence. A German-market query and a US-market query on the same string are two different searches with two different corpora, and comparing their counts measures the corpora rather than the interest. When you do want a comparison across markets, run each market as its own series and label it that way.

Location can be discarded without a word

Two documented cases make location vanish.

The first is validation. A value absent from Google's canonical place list never reaches Google, and the search proceeds as though you had left the option out (checked 2026-11-27, /docs/google_web_search). No error, no warning, no field in the response.

The second is the layout. Location only takes effect with the mobile device; paired with pc, placement comes from the exit IP and the value you sent goes unused (checked 2026-11-27, /docs/google_web_search).

Which means a perfectly reasonable-looking configuration - desktop layout plus a city - silently runs as an untargeted search. The fix is to treat the pair as invalid rather than to send both and hope.

A planner that shows the gap before you spend a request

The function below takes what you intend and what your policy is, and returns the body that will actually run along with every change it had to make.

import re

TBS_OK = ("qdr:", "cdr:", "cd_min:", "cd_max:", "sbd:", "li:")

def plan(intent: str, policy: dict) -> dict:
    notes, body = [], {}
    squeezed = re.sub(r"\s+", " ", intent).strip()
    if squeezed != intent:
        notes.append("whitespace normalised")
    gl, hl = policy.get("gl", "us"), policy.get("hl", "en")
    device = policy.get("device", "mobile")
    body.update(q=squeezed, gl=gl, hl=hl, device=device)
    if "gl" not in policy or "hl" not in policy:
        notes.append(f"market defaulted to {gl}/{hl}")
    for flag, key, val in (("exact", "nfpr", "1"), ("no_personalisation", "pws", "0"),
                           ("include_omitted", "filter", "0")):
        if policy.get(flag):
            body[key] = val
    tbs = policy.get("tbs")
    if tbs and all(p.startswith(TBS_OK) for p in tbs.split(",") if p):
        body["tbs"] = tbs
    elif tbs:
        notes.append("tbs refused: not name:value pairs")
    loc = policy.get("location")
    if loc and device == "mobile":
        body["location"] = loc
    elif loc:
        notes.append(f"location dropped: {device} layout ignores it")
    return {"body": body, "notes": notes}

The interesting output is notes. Every entry is a difference between the search you meant and the search that will execute, and each one is cheaper to read now than to discover from a strange result later.

What to do differently

Three habits follow, and none of them costs a request.

Write the effective query into your log next to the raw one, taken from the response rather than reconstructed. Pin the switches that matter to your product's correctness instead of accepting all five defaults. And when a result surprises you, diff the two request bodies before diffing the responses, because the answer is usually visible there and invisible everywhere else.

The parameters and switches quoted above are documented at https://serpbase.dev/?utm_campaign=ops-222e35a2a81a&utm_medium=outreach&utm_source=opsbot