Repository navigation
Extending FailureClassifier
A
FailureClassifierturns a failed agent query and its error message into identifier-only feedback records, such as "unknown columnamountinshop.orders". Built-ins cover common messages for type mismatches, unknown columns, unknown tables and ambiguous columns; add your own for messages they do not recognise. A classifier never sees the store and never keeps SQL text; when unsure it should return nothing.
class FailureClassifier(Protocol):
def classify(self, sql: str, error: str, dialect: str | None) -> list[FeedbackRecord]: ...
@dataclass(frozen=True)
class FeedbackRecord:
table: ObjectRef | None # as the SQL wrote it; intake resolves it to a stored table
column: str | None
failure_class: Literal["type_mismatch", "unknown_column", "unknown_table", "ambiguous_column"]Intake resolves each record's table against the store (a unique match, schema optional) and skips records it cannot attribute. Blank string literals before reading tokens from the SQL; the built-ins do.
class UnrecognizedName:
"""BigQuery-style 'Unrecognized name: amount' -> unknown_column on the only table in the SQL."""
_err = re.compile(r"Unrecognized name: (\w+)")
_from = re.compile(r"\b(?:FROM|JOIN)\s+([\w.]+)", re.IGNORECASE)
def classify(self, sql, error, dialect):
m, t = self._err.search(error), self._from.findall(sql)
if not m or len(t) != 1:
return [] # not sure: record nothing
table = ObjectRef.parse(t[0])
return [FeedbackRecord(table, m.group(1), "unknown_column")]
MY_CLASSIFIERS = (*BUILTIN_CLASSIFIERS, UnrecognizedName())
MY_CLASSIFIERS = (*BUILTIN_CLASSIFIERS, UnrecognizedName())(With from schemaguru.feedback import BUILTIN_CLASSIFIERS, FeedbackRecord and
from schemaguru.model.refs import ObjectRef.) Guru.report_error uses the built-ins; to use
yours, call the intake function directly:
from schemaguru.feedback import report_error
report_error(guru.store, "SELECT amount FROM shop.orders",
"Unrecognized name: amount at [1:8]", "bigquery", classifiers=MY_CLASSIFIERS)
# 1 (real result on the shop fixture: one record written)To run one on every report, register it: schemaguru.feedback.register_failure_classifier(c)
(it runs after the built-ins), or install it through the entry-point group
schemaguru.failure_classifiers; a plugin that fails to load is skipped with SG108.
def test_unrecognized_name():
recs = UnrecognizedName().classify("SELECT amount FROM shop.orders",
"Unrecognized name: amount at [1:8]", "bigquery")
assert [(r.table.canonical(), r.column) for r in recs] == [("shop.orders", "amount")]
def test_negative_control_two_tables_is_unsure():
sql = "SELECT amount FROM shop.orders JOIN shop.payments USING (order_id)"
assert UnrecognizedName().classify(sql, "Unrecognized name: amount", None) == []SchemaGuru is open source under the MIT License, Copyright (c) 2026 Rupak Chakraborty · Repository · Issues · This wiki is generated from docs/wiki/; edit it there, not here.
Start here
Components
- Catalog and Crawl
- Store
- Measurement
- Sampling
- Join Graph
- Path Search and Hub Guard
- Waypoint Rules
- Drafting
- PII and Sampling Policy
- Overlays
- Scoping
- Rendering
- Refresh and Drift
- Feedback and Guard
- Server
- Agent Integration
Using it
Warehouses
- BigQuery
- Snowflake
- Redshift
- Databricks
- PostgreSQL
- DuckDB
- ClickHouse
- SQL Server / Synapse
- Oracle
- Trino
- MySQL / MariaDB
Extending
- CatalogReader
- Store
- Retriever and Embedder
- TokenCounter
- LLMProvider
- PII Detector
- FailureClassifier
- FactKind
- Profile and Format
- ChangeClassifier
- JoinCandidateSource (planned)
- Authenticator
Project