find_pk_candidates
Find columns in a table that could serve as primary keys, using declared constraints and uniqueness/nullability checks. Returns candidates with evidence to guide schema analysis.
Instructions
Identify columns that meet primary key candidacy criteria.
EXPERIMENTAL — Results are based on common heuristics but have not been battle-tested for utility. They may contain false positives or exclude valid candidates. Use as a starting point for investigation, not as definitive answers.
Discovers PK candidates via two approaches:
Constraint-backed: Columns with declared PK or UNIQUE constraints
Structural: Columns that are unique, non-null, and match the type filter
Does not detect composite keys. Structural uniqueness checks query the full table and may be slow on very large tables.
Args: connection_id: Connection ID from connect_database table_name: Table to search for PK candidates. May be dotted (e.g. 'schema.table' or 'catalog.schema.table') and is resolved against the dialect. schema_name: Schema name. Defaults to the dialect's default schema (e.g. 'dbo' on MSSQL) when omitted. type_filter: SQL types considered for structural PK candidacy. Default: ["int", "bigint", "smallint", "tinyint", "uniqueidentifier"]. Set to empty list to disable type filtering. catalog: Optional Databricks catalog name. Rejected on non-Databricks dialects (returns an error response). On Databricks the catalog is threaded end-to-end (IDENT-08): the existence check and PK discovery run against the requested catalog via catalog-scoped reflection (cross-catalog supported — no default-catalog binding required).
Returns: TOON-encoded string with status, table/schema metadata, and candidates list:
status: "success" | "error"
table_name: string // on success only
schema_name: string // on success only
candidates: list // on success only
column_name: string
data_type: string
is_constraint_backed: bool
constraint_type: "PRIMARY KEY" | "UNIQUE" | null
is_unique: bool // all values distinct
is_non_null: bool // no nulls
is_pk_type: bool // data_type matches type_filter
error_message: string // on error onlyError conditions: - Invalid connection_id: returns status "error" with error_message - Table not found: returns status "error" with error_message - No candidates found: returns status "success" with empty candidates list
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| catalog | No | ||
| table_name | Yes | ||
| schema_name | No | ||
| type_filter | No | ||
| connection_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |