AI.SCORE takes a prompt describing what “good” looks like, runs it against a generative model, and returns a FLOAT64. That’s the whole function. No classification labels, no structured schema to define first, just a number that reflects however you’ve defined the scoring criteria in plain English.
We’re now ten entries into this series now, and the pattern keeps repeating. AI.KEY_DRIVERS, AI.FORECAST and AI.CAUSAL_EFFECT worked on numbers. AI.AGG, AI.CHUNK_DOCUMENT, and AI.PARSE_DOCUMENT worked on text and documents. This one scores anything you can describe in a prompt, and returns a number you can sort, filter and chart like any other column.
If you’ve used AI.GENERATE_DOUBLE, AI.SCORE will look familiar, because it’s solving the same problem: get a numeric judgement out of a model rather than text you then have to parse. AI.SCORE is the managed version aimed specifically at scoring and rating tasks, with retry handling and error-ratio tolerance built in, rather than something you wire up yourself around a general-purpose generation call.
We’re building this example on the same demo dataset we’ve used throughout this series. If you haven’t set it up, the setup guide walks through it, including the customer_note column we added for the AI.AGG article, which we’re reusing here.
Syntax
AI.SCORE(
PROMPT
[, connection_id => 'CONNECTION']
[, endpoint => 'ENDPOINT']
[, max_error_ratio => MAX_ERROR_RATIO]
)
PROMPT is the only required argument: a string, or a STRUCT combining a string with a column reference, describing what to score and how. Everything else is optional. Leave connection_id and endpoint unset, as every query in this article does, and BigQuery handles both for you, routing the call through your project’s default connection to a recent Gemini model. max_error_ratio sets the fraction of rows that are allowed to fail inference before the whole query errors out, which we’ll come back to later.
The function returns FLOAT64. A row that fails inference for a reason within your error tolerance returns NULL rather than failing the query outright.
Scoring customer notes for urgency
Every order in bq_ai_demo.ecommerce_orders that has a customer_note is a short piece of free text, and a chunk of the Electronics notes carry a Bluetooth pairing complaint we planted when we added the column. A support team reading these one at a time would eventually notice the pattern. AI.SCORE gets there without anyone reading anything:
SELECT
order_id,
product_category,
customer_note,
AI.SCORE(
'Score how urgent this customer note is for a support team to '
|| 'follow up on, from 0.0 (no action needed) to 1.0 (needs an '
|| 'urgent response). Note: ' || customer_note
) AS urgency_score
FROM
`bq_ai_demo.ecommerce_orders`
WHERE
customer_note IS NOT NULL
ORDER BY
urgency_score DESC
LIMIT 20;
The Bluetooth complaints land near the top. So do a handful of other notes we hadn’t specifically flagged when we wrote the column, which is the actual point of the exercise: a human skimming a sample would catch the obvious pattern and miss the rest.

Scoring and filtering in one pass with AI.IF
Sorting by score and taking the top 20 is fine for a sample. For an actual triage queue, you want a hard cutoff, and the cleanest way to get one is to combine AI.SCORE with AI.IF in the same SELECT, rather than scoring everything and filtering afterwards in a second query:
SELECT
order_id,
product_category,
customer_note
FROM
`bq_ai_demo.ecommerce_orders`
WHERE
customer_note IS NOT NULL
AND AI.IF(
'Does this customer note describe a product problem serious '
|| 'enough that a support agent should follow up today? Note: '
|| customer_note
);
This isn’t quite the same question as the urgency score above; AI.IF is answering a yes/no triage question rather than producing a ranked number. We’d usually reach for one or the other depending on whether the output is going into a dashboard (score, so it can be sorted and thresholds can move) or straight into an operational filter (AI.IF, so the logic lives in the WHERE clause). Running both side by side on the same notes is a reasonable way to sanity-check that they’re pointing in the same direction before you commit to either one in production.
Scoring images, not just text
AI.SCORE isn’t limited to text columns. Our ecommerce dataset doesn’t include product photos, so this is the one example in this article we’re borrowing from Google’s own public sample bucket rather than our shared dataset, the same way the AI.PARSE_DOCUMENT article did for its document examples. Google’s cymbal_pets sample dataset includes a product_images object table, and AI.SCORE can rate what’s in each image directly, via an ObjectRef column and OBJ.GET_READ_URL:
SELECT
uri,
AI.SCORE(
prompt => (
'Rate how clearly this product photo shows the full item '
|| 'against a plain background, from 0.0 (unusable) to 1.0 '
|| '(catalogue-ready).',
ref
),
connection_id => 'myproject.us.myconnection',
endpoint => 'gemini-2.5-flash'
) AS photo_quality_score
FROM
`bigquery-public-data.cymbal_pets.product_images`
ORDER BY
photo_quality_score ASC
LIMIT 10;
Sorting ascending here surfaces the worst photos first, which is the practical use case: a merchandising team isn’t short of good photos, they’re short of time to find the bad ones before a product page goes live.
The gotcha: a vague prompt gives you a vague score
The failure mode we kept hitting while writing this article wasn’t a syntax error, it was asking for a score without defining the scale precisely enough. “Rate how good this product photo is” produces scores that cluster in a narrow band in the middle, because the model has nothing to anchor against. Naming both ends of the scale, as we did above (“0.0 (unusable) to 1.0 (catalogue-ready)”), spreads the results out into something you can actually threshold on.
The same applies to the urgency example. An early draft of that prompt just said “score how urgent this is,” and the scores were technically ordered correctly but bunched between 0.4 and 0.7 for almost everything. Anchoring the ends (“0.0 no action needed” to “1.0 needs an urgent response”) fixed it. If your scores all come back looking suspiciously similar, the prompt is almost always the first place to look, not the model.
Picking a model or connection explicitly
Every query above leaves endpoint and connection_id unset. That’s deliberate, and it’ll work for most people reading this: BigQuery’s managed AI functions route through a default connection in your own project automatically, so there’s nothing to create first.
Two reasons to override the defaults anyway. First, stability: the default model can change over time, and a prompt tuned against one model’s behaviour won’t necessarily score the same way on its successor, so pinning endpoint is worth doing before anything goes into a production pipeline:
AI.SCORE(
'Score how urgent this customer note is, from 0.0 to 1.0.' || customer_note,
endpoint => 'gemini-2.5-flash'
)
Second, a specific connection: if you need the call to run through a particular Cloud resource connection (one in a different project or region, or one with specific IAM-delegated permissions), set connection_id to that connection’s full identifier, in the form project.location.connection_name, matching a real connection you’ve created in the BigQuery console’s Connections page. That identifier is never myproject.us.myconnection typed literally, that’s a placeholder standing in for your own values, and typing it in as-is will fail with a “project not found” error since there’s no actual project called myproject.
Handling inference errors with max_error_ratio
A note with unusual characters, an image that fails to load, a response the model declines to generate: any of these can make a single row fail inference. Without max_error_ratio, one bad row fails the entire query. Setting it to a tolerance lets the good rows through and returns NULL for the ones that failed:
SELECT
order_id,
customer_note,
AI.SCORE(
'Score the sentiment of this customer note from -1.0 (very '
|| 'negative) to 1.0 (very positive). Note: ' || customer_note,
max_error_ratio => 0.05
) AS sentiment_score
FROM
`bq_ai_demo.ecommerce_orders`
WHERE
customer_note IS NOT NULL;
A max_error_ratio of 0.05 tolerates failures on up to 5% of rows before the query errors out. Set it too high, and a genuine, widespread problem (an expired connection, a model that’s been deprecated) gets silently swallowed as a handful of NULLs instead of surfacing as the hard failure it should be. We’d rather see a query fail loudly on a real problem than quietly return 15% NULLs and have nobody notice until a report looks wrong weeks later.
What this is useful for
Most of what we’ve described above sounds like a nice-to-have on a demo table. It stops being one the moment a brand has thousands of support notes, product photos, or review snippets and a team too small to read all of them. AI.SCORE doesn’t replace a human making the final call on a flagged item; it replaces the much larger pile of items nobody was ever going to get to otherwise, by turning “is this worth looking at” into a column you can sort, filter and build a dashboard threshold around.
The thing to resist is treating the score as more precise than it is. These are judgements from a language model following a prompt, not a measurement. Validate against a sample you’ve checked by hand before you let a threshold decide anything automatically, and revisit that validation if you change the prompt, the model, or the kind of text you’re scoring.
Newsletter
Occasional notes on data, tracking & AI-readiness
No spam, no growth-hacking. Just an email when there's something worth reading.