Skip to content

Follow-ups from #622: SQL error filter vs blank error messages, tests and docs #623

Backlog

Description

@caohy1988

Follow-ups from reviewing #622 at 656d56f. None of these block that PR.

1. The SQL error filter and the in-memory check now disagree on a blank error message. This one matters most. After #622, has_error_signal in udf_kernels.py treats an empty or placeholder error_message ("", null, nan and so on) as no error, and Span.has_error uses it. TraceFilter(has_error=...) in trace.py and ERROR_SQL_PREDICATE / NO_ERROR_SQL_PREDICATE in event_semantics.py still only check whether the column is NULL. Take a session whose only completion row has status OK and error_message = "". list_traces(TraceFilter(has_error=True)) returns it, but its error_spans is empty. SDK.md describes the two as one shared definition.
Suggested fix: give the SQL predicates the same trimmed, case-insensitive missing-text test and null-safe status comparison the kernel uses. Then build the TraceFilter conditions from that predicate and its negation, and reuse it in the similar summary queries in system_evaluator.py and insights.py. A test that runs the SQL predicates and the Python check on the same rows would keep them in sync.

2. The new anchor test doesn't pin which row is chosen. The nullable-status case in tests/test_span_taxonomy.py only sets the missing-completion flag. That category always targets the last span, so the test would still pass if a <NA> row were wrongly picked as a direct error anchor. To cover it, use a nullable first row, a middle ERROR row and a final OK completion with the process-failed verdict, and assert that the middle span is the target.

3. UDF parity tests are skipped entirely without pandas/NumPy. In tests/test_udf_sql_generation.py the optional imports now come before the plain-string cases, so without those packages the existing cases are skipped instead of run. Keep the plain cases unconditional and move the pandas/NumPy cases into their own tests.

4. Docs and wording. These no longer match the new behavior:

  • The Span.has_error / Span.is_error docstrings still say a "populated" or "set" error message counts.
  • The label_failed_session_spans docstring still describes a raw status == "ERROR" check.
  • The CHANGELOG entry calls tool outcomes status-only, but tool_outcome also gives TOOL_ERROR precedence.

Activity

  1. caohy1988 commented on Nov 29, 2026

    @caohy1988
    CollaboratorAuthor

    One more item from looking at #622 again as merged at 697843b, not covered above.

    The checked-in UDF registration still has the old error logic. #622 changed the generated bodies in udf_sql_templates.py, but deploy/python_udf/register.sql (referenced from deploy/python_udf/README.md and examples/python_udf_event_semantics.sql) still uses error_message is not None and the old raw status comparison. Someone who redeploys from the quick start gets the old classifier back, so a successful tool completion with error_message = "" still counts as an error there, while the generated UDF and the Python kernel say it isn't. Before #622 both install paths agreed. Suggested fix: regenerate both bodies in register.sql from the templates, and add a test that runs the functions from the shipped file and the freshly generated ones against the same rows (blank message, real message, ERROR status) so the two stay in sync.

    Minor, and already noted in the PR: _streaming_evaluation.py still compares status == "ERROR" directly, so it has the same nullable-status problem if that path ever sees pd.NA.

  2. caohy1988 commented on Nov 29, 2026

    @caohy1988
    CollaboratorAuthor

    A few more from reviewing #624 at 10d24b9. None of them block it.

    • The customer guide now describes behavior the notebook's release doesn't have. docs/guides/bqca-prompt-response-logging-manual.md documents the new predicate, but the notebook it accompanies (examples/bqca_prompt_response_logging_customer_notebook.ipynb) installs v0.5.4, which still uses error_message IS NOT NULL. The guide's standalone triage query (Check Overhaul README, add documentation indexes, and fix CI issues #4) also still uses the plain null test. So a successful LLM_RESPONSE with an empty error message still shows up there as an error. Either say which release the new behavior is in, or show the normalized SQL in both places.
    • Other checked-in deploy SQL still uses the old check. Besides deploy/python_udf/register.sql (noted above), several continuous-query and streaming SQL files under deploy/ still test error_message IS NOT NULL. They should be updated along with register.sql. The shipped bqaa_tool_outcome body there also still raises on a pd.NA status.
    • The all-NULL case in tests/test_event_semantics.py would pass with the classification reversed. It only checks that exactly one of the two predicates is true. Asserting (error, no_error) == (0, 1) for that row, and adding a (NULL, NULL, 'ERROR') row that expects (1, 0), would pin it down.
    • Minor: the SQLite parity test doesn't model BigQuery's TRIM for tabs and newlines (SQLite only strips spaces). Real BigQuery should agree with Python here, and the PR already calls this out, so this is just worth remembering if the test is extended.
  3. caohy1988 commented on Nov 29, 2026

    @caohy1988
    CollaboratorAuthor

    A few more from reviewing #625 at b402320. None of them block it.

    • Alerting can now miss model errors that have an empty message. deploy/continuous_queries/pubsub_alerting.sql, realtime_error_analysis.sql and examples/continuous_query_alerting.sql only recognize event_type = 'TOOL_ERROR' by type, and now rely on the message for everything else. Before, a non-empty-but-blank message still let the row through. The plugin logs model errors as LLM_ERROR with str(error) and the default OK status, and some exceptions (an async timeout, for example) stringify to "". Those rows used to alert (medium in the example) and now drop out, while session_scoring and bigtable_dashboard still count them. This seems worth fixing soon: use ENDS_WITH(event_type, '_ERROR') in the three filters (qualified as e.event_type in the realtime query), let the example's medium branch accept any remaining _ERROR type, and add an ('LLM_ERROR', '', 'OK') row to the WHERE tests (registering an ENDS_WITH helper in SQLite).
    • The example's severity CASE isn't exercised. The test checks the literal list appears in the file and runs only the WHERE clause, so flipping NOT IN to IN in the medium branch keeps every test green. Running the shipped CASE on a message-only error, a placeholder message and overlapping type/status rows would cover it.
    • An extra function definition in register.sql would go unnoticed. The block regex needs a description comment right before CREATE OR REPLACE FUNCTION, so an uncommented second bqaa_is_error_event later in the file (which would win at deploy time) isn't checked. Counting every CREATE ... FUNCTION declaration and requiring exactly one per expected name would close that.
    • Minor: SQLite's TRIM only strips spaces, so tab- or newline-only messages aren't covered by the parity checks. The PR already notes this.
    • Still open from this issue: dashboards/ and the streaming-evaluation trigger keep the plain null check, as the PR says.
  4. caohy1988 commented on Nov 30, 2026

    @caohy1988
    CollaboratorAuthor

    Two more from re-checking #625 at a02e671, after it merged main. Neither blocks it.

    • A changelog entry would help now. The PR skipped one because fix(event_semantics): match the SQL error predicates to the Python kernel #624 was editing CHANGELOG.md, but fix(event_semantics): match the SQL error predicates to the Python kernel #624 is merged now. Anyone who re-registers the UDFs or restarts the continuous queries will see different alerting and is_error values, so a short Fixed entry covering register.sql, the four continuous queries and the example would be useful.
    • is_error now reports FALSE instead of NULL when the type or status is missing. Wrapping each part in COALESCE(..., FALSE) in bigtable_dashboard.sql and session_scoring.sql turns rows like (NULL, NULL, NULL) or ('LLM_REQUEST', NULL, NULL) from NULL into FALSE. That matches the SDK predicate and looks intentional, but it changes the values sink consumers see, so it's worth saying so in the changelog entry. (The Python UDF still raises on a NULL event_type, as before.)
    • Minor: the parity test compares the DDL header by splitting on whitespace, which would also hide a spacing change inside the quoted description. It only affects metadata.
  5. caohy1988 commented on Nov 30, 2026

    @caohy1988
    CollaboratorAuthor

    A few more from reviewing #627 at 7c1034c. None of them block it. The alerting-filter miss above is fixed there.

    • The suffix tests would pass with a two-name allowlist. tests/test_deploy_sql_parity.py only uses LLM_ERROR and TOOL_ERROR as type-only errors, so replacing ENDS_WITH(event_type, '_ERROR') with event_type IN ('TOOL_ERROR', 'LLM_ERROR') keeps all 16 tests green. Adding ('AGENT_ERROR', None, 'OK') and ('INVOCATION_ERROR', '', 'OK') to the plain rows and the medium-severity cases would pin the general rule. NULL-type rows for the WHERE test would also help: (None, 'boom', 'OK') should match and (None, None, None) should not.
    • The realtime classifier gets no error text for type-only rows. realtime_error_analysis.sql builds the prompt as CONCAT(..., 'Error: ', e.error_message). An empty message gives a prompt with nothing after Error: , and a NULL message makes the whole prompt NULL. Using something like COALESCE(NULLIF(TRIM(e.error_message), ''), CONCAT('event_type=', e.event_type)) would keep some signal. This was already the case for TOOL_ERROR.
    • That same query calls AI.GENERATE_TEXT like a scalar function. It passes a scalar CONCAT(...) and reads .ml_generate_text_llm_result. The documented form takes a table or query with a prompt column and returns a result column. Moving the call into FROM, over a filtered query that projects the ids and the prompt, would match it. This is older than these PRs, and I haven't run it against live BigQuery.
    • The Pub/Sub destinations aren't full URIs. examples/continuous_query_alerting.sql and the TOPIC example in deploy/continuous_queries/pubsub_alerting.sql use a bare projects/PROJECT/topics/... path. The export option expects https://pubsub.googleapis.com/projects/PROJECT/topics/agent-errors. This is also older than these PRs.
  6. caohy1988 commented on Nov 30, 2026

    @caohy1988
    CollaboratorAuthor

    Item 2 is covered by #628 at fb46428. The new test uses a nullable first row, a middle ERROR row, and a final OK completion with a process_failed verdict, and it asserts the middle span is the direct target. The older nullable-status case still only exercises the missing-completion path, so this is the pin that issue asked for.

    The test uses pd.NA as the sentinel, which is the one a stringified non-OK check would misread. It does not try to cover None/NaT, a nullable row that also carries a message, or message-only selection; those are outside the item as written.

  7. haiyuan-eng-google commented on Nov 30, 2026

    @haiyuan-eng-google
    Collaborator

    @leninworld thanks for your contribution and please help do me a favor to star the repo once you have time to help promote this repo, thanks

  8. leninworld commented on Nov 30, 2026

    @leninworld
    Contributor

    @leninworld thanks for your contribution and please help do me a favor to star the repo once you have time to help promote this repo, thanks

    Just did it! Thank you @haiyuan-eng-google

  9. caohy1988 commented on Nov 30, 2026

    @caohy1988
    CollaboratorAuthor

    Item 3 is covered by #629 at 9a47983: the plain parity cases for is_error_event and tool_outcome now run without pandas or NumPy, and the optional-value cases sit in their own gated tests.

    One minor leftover, not worth blocking on: test_is_error_event_parity_pandas_values gates on both NumPy and pandas, but its np.str_("ERROR") case only needs NumPy, so with NumPy installed and pandas missing that case is skipped. That grouping was already there before this change, and pandas normally brings NumPy along, so the practical loss is small. If someone touches this file again, moving the np.str_ case into a NumPy-only test (or giving the test a name that doesn't imply pandas-only) would tidy it up.

  10. caohy1988 commented on Nov 30, 2026

    @caohy1988
    CollaboratorAuthor

    Two small follow-ups from #632 (at b3d29a7). Neither blocks it.

    • The declaration counter in tests/test_deploy_sql_parity.py (around lines 52 and 134) is a regex built around the generated file's layout, not a SQL lexer. Comment markers are stripped even when they sit inside a string literal. Only the AS r"""..."""; body form gets removed, and a semicolon inside a string counts as a statement boundary. So a string containing ; CREATE FUNCTION bqaa_is_error_event(...) counts as a second declaration. A '--' string earlier on the same line as a real duplicate hides it, and the test still passes. The shipped file never does this, so it's low priority. Scanning strings, backticked identifiers and comments in one pass, and counting only at statement boundaries, would make it robust.
    • The name normalization around line 141 keeps leading whitespace when the dotted parts are backticked with spaces around the dots. It also lowercases the name, which merges UDF names whose case differs. Taking the final identifier token and keeping its case would fix both. This is a nit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions