Skip to main content
Replace catalog, schema, table, endpoint, and version placeholders after discovery. Prefer task-specific functions over ai_query.

SQL

Pin structured task-specific outputs:
In the validated workspace, ai_extract expects a top-level field map, not a complete JSON Schema document with type, properties, or additionalProperties around it. Materialize the VARIANT once, then cast it into the business schema separately:
Version 2.1 returns a VARIANT envelope whose field values live under response.<field>.value; nested arrays retain the same value envelope. Inspect the representative output before writing casts. JSON null inside VARIANT is not SQL NULL; use is_variant_null(value) when distinguishing the two. For ai_classify, pass short canonical label values. Each label must stay within the workspace limit of 50 characters. Put the policy and label descriptions in content or supported instructions, not inside long label strings:
Use row-level error capture and structured output for ai_query:

SQL notebook source

Python notebook source

For ai_query in PySpark, keep the SQL expression explicit so named arguments remain visible:

Raw files and mixed document formats

Resolve the ThinkPlatform logical directory before generating notebook code:
Pass the returned URI through an input_path notebook/Job parameter. Do not derive a /Volumes/... path from the project catalog: the Datalake container and Unity Catalog schema layout are independent. Preview a representative file and select the reader from its record semantics. JSONL is row-oriented even when stored in one file:
Using binaryFile for JSONL produces one binary row per file, not one row per JSON record. Use directory reads and metadata columns instead of enumerating filenames; reserve binaryFile for whole binary documents:
Route by extension/content type before calling a document function:
  • ai_parse_document v2.0 was live-validated with PDF, DOCX, and PNG.
  • HTML was rejected with Unsupported file format: html; decode it as UTF-8 and retain DOM/heading/table boundaries in a compatible envelope or deterministic chunks.
  • Do not send plain text or HTML through a binary document parser merely because the directory is mixed.
  • A non-NULL parse result can still contain error_status; count both NULL and internal-error outputs.
  • ai_prep_search is beta. A successful DESCRIBE does not guarantee runtime success. If the representative run returns an internal platform error, stop retrying and deterministically chunk parsed title/section/text/table elements while retaining page/bbox/source metadata.

Fact-preserving text transforms

ai_summarize is appropriate for ordinary summaries, but a representative run can omit operational facts. For strict handover text, define the required fact classes (identifiers, numbers, units, times, states, actions, safety statements, and follow-up owners), inspect every bounded validation output, and reject summaries that add outcomes or causal claims absent from the source. If a task-specific result cannot satisfy that contract, use a constrained generation function and keep the same independent fact gate in production. Masking functions can also hide approved non-personal identifiers. When a business identifier must survive masking, replace only an explicit allowlisted value with a collision-resistant placeholder before the AI expression, restore it deterministically afterward, and verify both sensitive-value absence and allowlisted-value presence. Translation functions can be technically correct while using terminology that is too general for the operating domain. Keep the raw translation immutable, apply only an explicit reviewed terminology map in a downstream stage, and inspect every bounded validation pair for identifiers, equipment terms, negation, and temporal qualifiers. ai_analyze_sentiment can return mixed in addition to positive, negative, and neutral. When the consumer requires three labels, define the normalization policy before production (for example, map mixed to neutral) and retain or audit the native label so the policy is visible. ai_similarity returns a score, not a universal duplicate decision. Calibrate the threshold with labeled positive and negative pairs, record it as a Job parameter, require margin between classes, and periodically re-evaluate it. Live validation showed small score variation between representative and production calls, so avoid thresholds that sit close to observed examples.

Serverless materialization and retry safety

AI expressions can be reevaluated by every DataFrame action. Materialize each expensive step exactly once, then run counts, transformations, and quality checks against Delta:
Use a new run suffix rather than overwriting an existing table. CREATE TABLE IF NOT EXISTS makes a retry reuse an already completed stage after an unrelated notebook failure. Avoid .write.mode("errorifexists").saveAsTable(...); the live Serverless environment rejects that mode.

Quality gates

Validate from an independent SQL Statement after the Job succeeds:
  • raw inputs, output rows, and distinct source IDs agree;
  • required values, internal error fields, invalid labels, duplicates, and empty outputs are counted;
  • structured values cast to the intended DATE/DECIMAL/ARRAY/STRUCT types;
  • identifiers, dates, numbers, units, and source/page locations are retained;
  • fields that were not explicit in the source remain NULL; instructions alone can still permit arithmetic or date inference, so use a deterministic source-evidence gate for strict extraction;
  • representative original/output pairs are inspected for semantic drift.
Task-specific text transforms are model operations, not deterministic linters. For strict grammar-only requirements, ai_fix_grammar still needs a semantic-preservation gate; a successful run alone is not acceptance.

Explicit Unity Catalog SQL wrapper

Create only when the user wants a stable shared abstraction. Keep it inside the project catalog and use LANGUAGE SQL:
ThinkPlatform deliberately rejects Python, JAR, external, permission-changing, and DROP FUNCTION statements through the project SQL policy.