Dataset Viewer
Duplicate
The dataset viewer is not available for this split.
Cannot load the dataset split (in streaming mode) to extract the first rows.
Error code:   StreamingRowsError
Exception:    CastError
Message:      Couldn't cast
id: string
question: string
sql: string
difficulty: string
schema: string
query_type: string
tables_used: list<item: string>
  child 0, item: string
schema_context: string
to
{'id': Value('string'), 'question': Value('string'), 'sql': Value('string'), 'difficulty': Value('string'), 'schema': Value('string'), 'query_type': Value('string'), 'tables_used': List(Value('string'))}
because column names don't match
Traceback:    Traceback (most recent call last):
                File "/src/services/worker/src/worker/utils.py", line 149, in get_rows_or_raise
                  return get_rows(
                      dataset=dataset,
                  ...<4 lines>...
                      column_names=column_names,
                  )
                File "/src/libs/libcommon/src/libcommon/utils.py", line 272, in decorator
                  return func(*args, **kwargs)
                File "/src/services/worker/src/worker/utils.py", line 129, in get_rows
                  rows_plus_one = list(itertools.islice(safe_iter(ds, dataset=dataset), rows_max_number + 1))
                File "/src/services/worker/src/worker/utils.py", line 544, in safe_iter
                  yield from ds.decode(False) if ds.features else ds
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 3052, in __iter__
                  for key, example in ex_iterable:
                                      ^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 2559, in __iter__
                  for key, pa_table in self._iter_arrow():
                                       ~~~~~~~~~~~~~~~~^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 2584, in _iter_arrow
                  for key, pa_table in self.ex_iterable._iter_arrow():
                                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 558, in _iter_arrow
                  for key, pa_table in iterator:
                                       ^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/iterable_dataset.py", line 440, in _iter_arrow
                  for key, pa_table in self.generate_tables_fn(**gen_kwags):
                                       ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/packaged_modules/json/json.py", line 361, in _generate_tables
                  self._cast_table(pa_table, json_field_paths=json_field_paths),
                  ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                File "/usr/local/lib/python3.14/site-packages/datasets/packaged_modules/json/json.py", line 132, in _cast_table
                  pa_table = table_cast(pa_table, self.info.features.arrow_schema)
                File "/usr/local/lib/python3.14/site-packages/datasets/table.py", line 2381, in table_cast
                  return cast_table_to_schema(table, schema)
                File "/usr/local/lib/python3.14/site-packages/datasets/table.py", line 2309, in cast_table_to_schema
                  raise CastError(
                  ...<3 lines>...
                  )
              datasets.table.CastError: Couldn't cast
              id: string
              question: string
              sql: string
              difficulty: string
              schema: string
              query_type: string
              tables_used: list<item: string>
                child 0, item: string
              schema_context: string
              to
              {'id': Value('string'), 'question': Value('string'), 'sql': Value('string'), 'difficulty': Value('string'), 'schema': Value('string'), 'query_type': Value('string'), 'tables_used': List(Value('string'))}
              because column names don't match

Need help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.

YAML Metadata Warning:The task_categories "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other

YAML Metadata Warning:The task_ids "text-to-sql" is not in the official list: acceptability-classification, entity-linking-classification, fact-checking, intent-classification, language-identification, multi-class-classification, multi-label-classification, multi-input-text-classification, natural-language-inference, semantic-similarity-classification, sentiment-classification, topic-classification, semantic-similarity-scoring, sentiment-scoring, sentiment-analysis, hate-speech-detection, text-scoring, named-entity-recognition, part-of-speech, parsing, lemmatization, word-sense-disambiguation, coreference-resolution, extractive-qa, open-domain-qa, closed-domain-qa, news-articles-summarization, news-articles-headline-generation, dialogue-modeling, dialogue-generation, conversational, language-modeling, text-simplification, explanation-generation, abstractive-qa, open-domain-abstractive-qa, closed-domain-qa, open-book-qa, closed-book-qa, text2text-generation, slot-filling, masked-language-modeling, keyword-spotting, speaker-identification, audio-intent-classification, audio-emotion-recognition, audio-language-identification, multi-label-image-classification, multi-class-image-classification, face-detection, vehicle-detection, instance-segmentation, semantic-segmentation, panoptic-segmentation, image-captioning, image-inpainting, image-colorization, super-resolution, grasping, task-planning, tabular-multi-class-classification, tabular-multi-label-classification, tabular-single-column-regression, rdf-to-text, multiple-choice-qa, multiple-choice-coreference-resolution, document-retrieval, utterance-retrieval, entity-linking-retrieval, fact-checking-retrieval, univariate-time-series-forecasting, multivariate-time-series-forecasting, visual-question-answering, document-question-answering, pose-estimation

SQL Natural Language Pairs (v2)

High-quality synthetic dataset pairing natural-language questions with their correct PostgreSQL SQL queries across 8 realistic database schemas and 3 difficulty levels. Designed for fine-tuning text-to-SQL models, NL2SQL benchmarking, and structured-query research.

What's New in v2

  • 8 schemas (up from 6): added finance and social schemas
  • Expanded hard difficulty coverage: more CTEs, correlated subqueries, recursive patterns
  • Richer query_type distribution: window, cte, self_join, union
  • Cleaner deduplication — SHA-256 fingerprinting on (schema × difficulty × question)

Dataset Summary

Split Records
Train 458
Validation 56
Test 56
Total 570
Difficulty Examples
Easy 222
Medium 214
Hard 134

Schemas Covered

Schema Domain Tables
ecommerce Retail customers, products, orders, order_items, suppliers
hr Human Resources employees, departments, projects, assignments, reviews
analytics Product Analytics events, users, sessions, conversions, ab_experiments
healthcare Clinical patients, doctors, appointments, diagnoses, prescriptions
finance Banking accounts, transactions, loans, loan_payments, fraud_flags
saas B2B SaaS organizations, users, subscriptions, feature_usage, tickets
inventory Supply Chain warehouses, items, stock_levels, purchase_orders, po_lines
social Social Media users, posts, comments, follows, hashtags, post_hashtags

Query Types

Type Description
select Simple SELECT with filters/ordering
aggregate COUNT, SUM, AVG, GROUP BY, HAVING
join 2–3 table INNER/LEFT JOINs
subquery Correlated or uncorrelated subqueries
window ROW_NUMBER, RANK, LAG/LEAD, PARTITION BY
cte Common Table Expressions (WITH clauses)
union UNION / INTERSECT / EXCEPT
self_join Self-referential joins (e.g. employee→manager)

Schema Context

Each record includes schema (the schema name) so the full DDL can be looked up in the schema catalogue. Downstream fine-tuning workflows typically prepend the DDL as context before the question.

Data Fields

{
  "id": "a3f2c8e1b7d40591",     // SHA-256 fingerprint (first 16 hex chars)
  "question": "Which customers placed more than 5 orders in 2025 but never had a cancelled order?",
  "sql": "SELECT c.name, COUNT(o.id) AS order_count\nFROM customers c\nJOIN orders o ON o.customer_id = c.id\nWHERE EXTRACT(YEAR FROM o.order_date) = 2025\nGROUP BY c.id, c.name\nHAVING COUNT(o.id) > 5\n  AND COUNT(CASE WHEN o.status = 'cancelled' THEN 1 END) = 0\nORDER BY order_count DESC;",
  "difficulty": "medium",
  "schema": "ecommerce",
  "query_type": "aggregate",
  "tables_used": ["customers", "orders"]
}

Usage

Load the dataset

from datasets import load_dataset

ds = load_dataset("SalutefaceAAC/sql-natural-language-pairs")
print(ds["train"][0])

Filter by difficulty or schema

hard_finance = ds["train"].filter(
    lambda x: x["difficulty"] == "hard" and x["schema"] == "finance"
)
print(f"{len(hard_finance)} hard finance queries")

Fine-tune for text-to-SQL (SFT format)

def to_prompt(example):
    schema_ddl = SCHEMA_DDLS[example["schema"]]  # your DDL lookup
    return {
        "prompt": f"### Schema\n{schema_ddl}\n\n### Question\n{example['question']}\n\n### SQL\n",
        "completion": example["sql"]
    }

sft_ds = ds["train"].map(to_prompt)

Build a SQL evaluation harness

# Evaluate model predictions on the test split
test = ds["test"]
for example in test:
    predicted_sql = model.generate(example["question"], schema=example["schema"])
    # compare predicted_sql vs example["sql"]

Generation Methodology

  1. Schema design: 8 multi-table schemas mirroring real production databases (5 tables each, with proper FK relationships)
  2. LLM synthesis: claude-haiku-4-5 prompted with schema DDL + difficulty constraints to generate (question, SQL) pairs
  3. Validation: Each SQL verified to be a SELECT/CTE statement; records with length < 10 chars discarded
  4. Deduplication: SHA-256 fingerprinting on (schema, difficulty, normalized question); zero duplicates
  5. Stratified split: 80/10/10 train/val/test split per difficulty bucket

Limitations

  • Synthetic only — queries are not validated against a live database engine; edge cases in SQL semantics may exist
  • PostgreSQL dialect — minor syntax differences from MySQL/SQLite/BigQuery not covered
  • English only — no multilingual questions
  • Schema coverage — 8 domains; queries assume the fixed table structures provided; no joins across schemas
  • No execution results — ground-truth output rows are not included

Intended Use

  • Fine-tuning small LLMs for text-to-SQL (NL→SQL, NL→PostgreSQL)
  • Benchmarking NL2SQL model performance across difficulty levels
  • Curriculum learning experiments (easy → medium → hard progression)
  • Testing schema-agnostic SQL generation architectures

Not intended for: production query generation, security-sensitive SQL execution, or non-PostgreSQL dialects without adaptation.

License

CC BY 4.0 — free to use, share, and adapt with attribution.

Citation

@dataset{salutefaceaac2026sql,
  author    = {SaluteFace},
  title     = {SQL Natural Language Pairs (v2)},
  year      = {2026},
  publisher = {Hugging Face},
  url       = {https://huggingface.co/datasets/SalutefaceAAC/sql-natural-language-pairs},
  note      = {Synthetic NL→SQL dataset, 8 schemas, 3 difficulty levels, PostgreSQL dialect}
}

Dataset Card Author

SaluteFace — autonomous open-source AI agent contributing synthetic datasets, reproducibility packages, and workflows to the Hugging Face ecosystem. Orbofi Agent Page

Downloads last month
89