text2sql-query-optimizer

text2sql-query-optimizer is a skill for Claude Code, Codex from ibm-self-serve-assets/building-blocks. It costs 61 tokens per session (1,323 once invoked), scanned A, original, Apache-2.0.

Guidance for improving SQL written from plain-language questions by IBM watsonx.data Intelligence. It covers choosing models, matching SQL dialects, checking queries, and using metadata and feedback.

In plain words
What is it for?
Use it to select between Granite and Llama models, tune prompts and database dialects, validate tables and columns, investigate query errors, and design feedback loops for Text2SQL systems.
Why use it?
It helps diagnose inaccurate or unsafe generated queries before they run. It also provides ways to improve results when the database schema or model settings are causing errors.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to select between Granite and Llama models, tune prompts and…

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/ibm-self-serve-assets/building-blocks/text2sql-query-optimizer
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add ibm-self-serve-assets/building-blocks --skill text2sql-query-optimizer
Clone the repo
git clone --depth 1 https://github.com/ibm-self-serve-assets/building-blocks

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for text2sql-query-optimizer

README.md
[![agentmods](https://agentmods.dev/badge/skills/ibm-self-serve-assets/building-blocks/text2sql-query-optimizer.svg)](https://agentmods.dev/skills/ibm-self-serve-assets/building-blocks/text2sql-query-optimizer)
Your own site
<a href="https://agentmods.dev/skills/ibm-self-serve-assets/building-blocks/text2sql-query-optimizer"><img src="https://agentmods.dev/badge/skills/ibm-self-serve-assets/building-blocks/text2sql-query-optimizer.svg" alt="Measured on agentmods" height="20"></a>
Per session 61 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,323 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00061 $0.01323
Opus 5 $0.00030 $0.00661
Sonnet 5 $0.00012 $0.00265
Haiku 4.5 $0.00006 $0.00132

Measured 7d ago against content hash 9be1233dfa8d, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

text2sql-query-optimizer scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

resp = requests.post(url, headers={"Authorization": f"Bearer {token}"}, params=params, json=payload)
ibm-bob/skills/text2sql-query-optimizer/SKILL.md · 155 lines

How it starts

The opening of the file, as written. The whole thing — 155 lines — stays where its author put it; the contents beside it link to each section on GitHub.

watsonx.data Intelligence Text2SQL Query Optimizer

Purpose

Expert guidance for evaluating IBM watsonx.data Intelligence Text2SQL output quality, diagnosing poor query results, tuning model parameters, and implementing feedback loops to iteratively improve accuracy.

IBM Cloud Product Coverage

IBM Cloud Product Usage
watsonx.data Intelligence Text2SQL API: /semantic_automation/v1/text_to_sql
IBM watsonx.ai LLM selection: ibm/granite-3-8b-instruct, meta-llama/llama-3-3-70b-instruct
IBM Cloud IAM Bearer token authentication

Rules

  • Model selection: ibm/granite-3-8b-instruct for SQL-specialist tasks; meta-llama/llama-3-3-70b-instruct for complex multi-join queries
  • Always validate generated SQL before execution (syntax check, table/column existence)
  • Dialect must match target system: presto, postgresql, mssql, oracle, snowflake
  • Set "raw_output": false to get structured response with explanation
  • Enrich metadata before changing model — metadata quality has highest impact on accuracy

Scope

  • Text2SQL model selection and parameter tuning
  • Generated SQL validation and safety checks
  • Error pattern diagnosis and remediation
  • Quality evaluation metrics (exact match, execution accuracy)
  • Feedback loop implementation for iterative improvement

Procedure

Phase 1: Model Selection Guide

Model Strengths Use Case
ibm/granite-3-8b-instruct SQL-specialist, fast Standard OLAP queries
meta-llama/llama-3-3-70b-instruct Complex reasoning Multi-table JOINs, sub-queries
ibm/granite-20b-code-instruct Code generation Complex aggregations

Phase 2: Text2SQL API Request

import requests

def run_text2sql(query: str, dialect: str, model_id: str, project_id: str, token: str) -> dict:
    url = f"https://api.ca-tor.dai.cloud.ibm.com/semantic_automation/v1/text_to_sql"
    params = {
        "container_id": project_id,
        "container_type": "project",
        "dialect": dialect,
        "model_id": model_id,
    }
    payload = {"query": query, "raw_output": False}
    resp = requests.post(url, headers={"Authorization": f"Bearer {token}"}, params=params, json=payload)
    resp.raise_for_status()
    return resp.json()

Read the full file on GitHub · 155 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 155 lines · 61 tokens per session scan A 9be1233dfa8d

Subscribe to this mod's changes

text2sql-query-optimizer is a skill published in the GitHub repository ibm-self-serve-assets/building-blocks (24 stars, last pushed 12d ago), licensed Apache-2.0. It adds 61 tokens to every session and 1,323 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

Related

Other skills, from other repositories

natural-language-postgres

Chat app that lets you ask questions in plain English and query your PostgreSQL database.

rebyteai-template/rebyte-skills · 22 tokens

embeddings

Vector embeddings with HNSW indexing, sql.js persistence, and hyperbolic support. 75x faster with agentic-flow integration. Use when: semantic search, pattern matching, similarity queries, knowledge retrieval. Skip when: exact text matching, simple lookups, no semantic understanding needed.

ruvnet/ruflo · 62 tokens

llm-app-patterns

Production-ready patterns for building LLM applications. Covers RAG pipelines, agent architectures, prompt IDEs, and LLMOps monitoring. Use when designing AI applications, implementing RAG, building agents, or setting up LLM observability.

davila7/claude-code-templates · 54 tokens

prompt-optimization

Improve a prompt on the evaluations workbench through a measured loop. Score the baseline first, then duplicate the target column, form a hypothesis from failing rows, edit the copy's prompt draft, run, compare pass rate and cost, and repeat until the numbers hold. Use when the user asks to optimize or improve a…

langwatch/langwatch · 105 tokens

enhance-prompt

Transforms vague UI ideas into polished, Stitch-optimized prompts. Enhances specificity, adds UI/UX keywords, injects design system context, and structures output for better generation results.

google-labs-code/stitch-skills · 41 tokens

prompt-engineer

Writes, refactors, and evaluates prompts for LLMs — generating optimized prompt templates, structured output schemas, evaluation rubrics, and test suites. Use when designing prompts for new LLM applications, refactoring existing prompts for better accuracy or token efficiency, implementing chain-of-thought or few-shot…

Jeffallan/claude-skills · 93 tokens