Skip to content

Instantly share code, notes, and snippets.

@lopinho
Created September 18, 2025 23:27
Show Gist options
  • Select an option

  • Save lopinho/d4c94314d8f73da0b57eef99cba8fcf4 to your computer and use it in GitHub Desktop.

Select an option

Save lopinho/d4c94314d8f73da0b57eef99cba8fcf4 to your computer and use it in GitHub Desktop.
'\nSchema Context Builder Prompt\n\nYou are given:\n\n engine_name: postgresql\n user_intent: along the years, how bitcoin price changed?\n raw_metadata (JSON array, new column fields included): [{"name": "coinmetrics", "type": null, "comment": 0, "row_count": 294, "relevance_score": 4.0, "columns": [{"column_name": "price", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "total_bitcoins", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "time", "data_type": "timestamp with time zone", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "marketCap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "active_addresses", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "hashrate", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "volatility", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "txtfrcnt", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"time": "2022-10-21T02:00:00+00:00", "price": null, "marketCap": null, "total_bitcoins": null, "active_addresses": null, "hashrate": null, "volatility": 0.01667404969256819, "txtfrcnt": null}, {"time": "2022-10-22T02:00:00+00:00", "price": null, "marketCap": null, "total_bitcoins": null, "active_addresses": null, "hashrate": null, "volatility": 0.014155079939769962, "txtfrcnt": null}, {"time": "2022-10-25T02:00:00+00:00", "price": null, "marketCap": null, "total_bitcoins": null, "active_addresses": null, "hashrate": null, "volatility": 0.015633159651807633, "txtfrcnt": null}]}, {"name": "market_data", "type": null, "comment": 0, "row_count": 84286, "relevance_score": 2.0, "columns": [{"column_name": "price", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "coin", "data_type": "character varying", "is_nullable": "NO", "column_default": null, "character_maximum_length": 255, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "time", "data_type": "date", "is_nullable": "NO", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "market_cap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "total_volume", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"coin": "havven", "time": "2023-01-10", "price": 1.77, "market_cap": 424930175.0, "total_volume": 28292519.0}, {"coin": "binancecoin", "time": "2023-01-10", "price": 277.94, "market_cap": 45393402043.0, "total_volume": 313319088.0}, {"coin": "balancer", "time": "2023-01-10", "price": 5.63, "market_cap": 217326246.0, "total_volume": 6876862.0}]}, {"name": "on_chain", "type": null, "comment": 0, "row_count": 512, "relevance_score": 2.0, "columns": [{"column_name": "spotPrice", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "time", "data_type": "timestamp with time zone", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "marketcapUSD", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "hashrate", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "realizedcapUSD", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "daysSince", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "MVHR", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "symbol", "data_type": "text", "is_nullable": "YES", "column_default": "\'bitcoin\'::text", "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "MVRV", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"time": "2021-12-30T09:06:47+00:00", "marketcapUSD": null, "hashrate": null, "realizedcapUSD": null, "daysSince": 4.541213312548006, "spotPrice": 46876.00263382698, "MVHR": null, "symbol": "bitcoin", "MVRV": null}, {"time": "2023-02-25T00:00:00+00:00", "marketcapUSD": 447020226642.799, "hashrate": 227840889.77873334, "realizedcapUSD": 383783650608.05817, "daysSince": null, "spotPrice": null, "MVHR": 1961.9842034365329, "symbol": "bitcoin", "MVRV": 1.164771417267}, {"time": "2023-02-17T00:00:00+00:00", "marketcapUSD": 474775525177.3805, "hashrate": 321168408.7710616, "realizedcapUSD": 383573979505.54016, "daysSince": null, "spotPrice": null, "MVHR": 1478.2759207049364, "symbol": "bitcoin", "MVRV": 1.237767811543}]}, {"name": "chain_metrics", "type": null, "comment": 0, "row_count": 5541, "relevance_score": 2.0, "columns": [{"column_name": "price_usd", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "coin", "data_type": "character varying", "is_nullable": "NO", "column_default": null, "character_maximum_length": 255, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "time", "data_type": "date", "is_nullable": "NO", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "market_cap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "hash_rate", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "current_supply", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "active_address_count", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "transfer_count", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "realized_cap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "mvrv", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "volatility_30d", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "volatility_180d", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"coin": "bitcoin", "time": "2022-05-05", "price_usd": 36502.0245601403, "market_cap": 694694154668.1462, "hash_rate": 232530821.92495468, "current_supply": 19031660.92948013, "active_address_count": 1189734, "transfer_count": 942304, "realized_cap": 465191628859.07263, "mvrv": 1.493350506698, "volatility_30d": 0.031144805184373972, "volatility_180d": 0.033436785910590884}, {"coin": "bitcoin", "time": "2024-03-31", "price_usd": 71227.4517939801, "market_cap": 1401014986716.4766, "hash_rate": 566120367.485718, "current_supply": 19669592.99300506, "active_address_count": 691124, "transfer_count": 752627, "realized_cap": 549531275361.9261, "mvrv": 2.54947270434, "volatility_30d": 0.03917722715181363, "volatility_180d": 0.027206757821629804}, {"coin": "bitcoin", "time": "2024-07-20", "price_usd": 67185.4978112215, "market_cap": 1325455815468.5513, "hash_rate": 672971424.2421774, "current_supply": 19728302.36657367, "active_address_count": 673407, "transfer_count": 1097203, "realized_cap": 613766368214.9689, "mvrv": 2.159544550027, "volatility_30d": 0.025340656522741825, "volatility_180d": 0.02763388661575242}]}, {"name": "p2p_trade_by_region", "type": null, "comment": 0, "row_count": 360, "relevance_score": 0.0, "columns": [{"column_name": "time", "data_type": "date", "is_nullable": "NO", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "eastern_europe", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "latin_america", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "north_america", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "western_europe", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "asia_pacific", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "sub_saharan_africa", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "aus_nz", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "middle_east_north_africa", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "sum_regions_btc_volume", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"time": "2015-07-05", "eastern_europe": 635215, "latin_america": 118174, "north_america": 4126444, "western_europe": 2051156, "asia_pacific": 344566, "sub_saharan_africa": 196484, "aus_nz": 499609, "middle_east_north_africa": 11988, "sum_regions_btc_volume": 7983636}, {"time": "2015-07-12", "eastern_europe": 599789, "latin_america": 178807, "north_america": 4386854, "western_europe": 1796552, "asia_pacific": 323553, "sub_saharan_africa": 174492, "aus_nz": 496131, "middle_east_north_africa": 10845, "sum_regions_btc_volume": 7967023}, {"time": "2015-07-19", "eastern_europe": 571615, "latin_america": 113187, "north_america": 4396480, "western_europe": 1757334, "asia_pacific": 344669, "sub_saharan_africa": 246366, "aus_nz": 503517, "middle_east_north_africa": 12502, "sum_regions_btc_volume": 7945670}]}]\n\nTask\nProduce a concise, engine-aware schema context that a downstream model will use to translate natural-language requests into SQL.\n\nHard Requirements\n\n Return ONLY the formatted schema context text. No explanations, no labels, no wrappers.\n If raw_metadata is insufficient to generate a usable schema context, return exactly: I don\'t have enough data complete your request\n Preserve exact table and column names and case; do not invent or rename any identifiers.\n\nAbout raw_metadata (new format)\nEach table object contains: name, type, comment, row_count, relevance_score, columns (with column_name, data_type, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_scale, column_comment, is_primary_key, relevance_score), foreign_keys, and optional example_rows. Use example_rows only to inform relevance — do not emit them.\n\nFormatting (produce in this exact order)\n\n Engine Notes:\n\n Identifier quoting rule for postgresql\n Identifier case-sensitivity behavior for postgresql\n Case-insensitive string-match guidance for postgresql\n Date/time function hints for postgresql (current timestamp, truncation, casting)\n Row-limiting syntax for postgresql\n\n Tables (list in relevance order; prioritize tables/columns matching user_intent):\n\n Table: <fully qualified name if present; otherwise plain name>\n Columns: (order by column relevance_score or PK first)\n <column_name> (<data_type> [LEN <character_maximum_length>] [PREC <numeric_precision>,<numeric_scale>] [DEFAULT <column_default>] [PK if true] [NULLABLE/NOT NULL])\n Notes:\n Columns requiring quoting (mixed-case / special chars)\n Date/time columns and any type mismatches needing casts (e.g., DATE vs TIMESTAMP)\n Composite PKs or implied uniqueness (if discernible)\n\n Suggested Joins:\n\n List obvious join keys where names and types align (e.g., chain_metrics.coin = market_data.coin; chain_metrics.time = market_data.time)\n If date vs timestamp mismatch exists, show engine-specific CAST or date_trunc examples to align keys\n\n Possible Synonyms:\n\n List likely equivalent identifiers across tables (e.g., coin vs symbol) without renaming or enforcing joins\n\n Constraints and Query Hints:\n\n Primary-key composites or uniqueness implied by metadata\n Columns commonly used for filtering/sorting (time, price, market_cap, etc.)\n Remind that identifiers must match exactly and engine-specific quoting may be required\n\nEngine Presets (emit only the preset matching engine_name; include but do not alter the following examples)\n\n PostgreSQL:\n Quoting: "identifier"\n Case-insensitive match: ILIKE or LOWER(col)=LOWER(\'value\')\n Date/time: NOW(), CURRENT_DATE, date_trunc(\'day\', ts), CAST/::, ::date\n Limit: LIMIT n\n MySQL:\n Quoting: identifier\n Case-insensitive match: default collations; otherwise LOWER(...)\n Date/time: NOW(), CURDATE(), DATE_FORMAT, CAST/CONVERT\n Limit: LIMIT n\n SQL Server:\n Quoting: [identifier] (or "identifier" with QUOTED_IDENTIFIER ON)\n Case-insensitive match: depends on collation; otherwise LOWER(...)\n Date/time: GETDATE(), SYSUTCDATETIME(), DATEADD, DATEDIFF, FORMAT, CAST/CONVERT\n Limit: SELECT TOP n ...\n Oracle:\n Quoting: "identifier"\n Case-insensitive match: LOWER(col)=LOWER(\'value\') or NLSSORT/NLS_COMP\n Date/time: SYSTIMESTAMP, TRUNC(date), CAST, TO_DATE/TO_TIMESTAMP\n Limit: FETCH FIRST n ROWS ONLY or ROWNUM\n\nSelection & Compression Rules\n\n Use relevance_score and user_intent to order tables and columns.\n Do NOT emit example_rows; they are only for internal relevance inference.\n\nValidation\n\n Never invent tables, columns, types, or foreign keys not present in raw_metadata.\n Preserve schema prefixes if present.\n Maintain exact case for all identifiers.\n '
(Pdb) print(prompt)
Schema Context Builder Prompt
You are given:
engine_name: postgresql
user_intent: along the years, how bitcoin price changed?
raw_metadata (JSON array, new column fields included): [{"name": "coinmetrics", "type": null, "comment": 0, "row_count": 294, "relevance_score": 4.0, "columns": [{"column_name": "price", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "total_bitcoins", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "time", "data_type": "timestamp with time zone", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "marketCap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "active_addresses", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "hashrate", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "volatility", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "txtfrcnt", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"time": "2022-10-21T02:00:00+00:00", "price": null, "marketCap": null, "total_bitcoins": null, "active_addresses": null, "hashrate": null, "volatility": 0.01667404969256819, "txtfrcnt": null}, {"time": "2022-10-22T02:00:00+00:00", "price": null, "marketCap": null, "total_bitcoins": null, "active_addresses": null, "hashrate": null, "volatility": 0.014155079939769962, "txtfrcnt": null}, {"time": "2022-10-25T02:00:00+00:00", "price": null, "marketCap": null, "total_bitcoins": null, "active_addresses": null, "hashrate": null, "volatility": 0.015633159651807633, "txtfrcnt": null}]}, {"name": "market_data", "type": null, "comment": 0, "row_count": 84286, "relevance_score": 2.0, "columns": [{"column_name": "price", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "coin", "data_type": "character varying", "is_nullable": "NO", "column_default": null, "character_maximum_length": 255, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "time", "data_type": "date", "is_nullable": "NO", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "market_cap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "total_volume", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"coin": "havven", "time": "2023-01-10", "price": 1.77, "market_cap": 424930175.0, "total_volume": 28292519.0}, {"coin": "binancecoin", "time": "2023-01-10", "price": 277.94, "market_cap": 45393402043.0, "total_volume": 313319088.0}, {"coin": "balancer", "time": "2023-01-10", "price": 5.63, "market_cap": 217326246.0, "total_volume": 6876862.0}]}, {"name": "on_chain", "type": null, "comment": 0, "row_count": 512, "relevance_score": 2.0, "columns": [{"column_name": "spotPrice", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "time", "data_type": "timestamp with time zone", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "marketcapUSD", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "hashrate", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "realizedcapUSD", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "daysSince", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "MVHR", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "symbol", "data_type": "text", "is_nullable": "YES", "column_default": "'bitcoin'::text", "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "MVRV", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"time": "2021-12-30T09:06:47+00:00", "marketcapUSD": null, "hashrate": null, "realizedcapUSD": null, "daysSince": 4.541213312548006, "spotPrice": 46876.00263382698, "MVHR": null, "symbol": "bitcoin", "MVRV": null}, {"time": "2023-02-25T00:00:00+00:00", "marketcapUSD": 447020226642.799, "hashrate": 227840889.77873334, "realizedcapUSD": 383783650608.05817, "daysSince": null, "spotPrice": null, "MVHR": 1961.9842034365329, "symbol": "bitcoin", "MVRV": 1.164771417267}, {"time": "2023-02-17T00:00:00+00:00", "marketcapUSD": 474775525177.3805, "hashrate": 321168408.7710616, "realizedcapUSD": 383573979505.54016, "daysSince": null, "spotPrice": null, "MVHR": 1478.2759207049364, "symbol": "bitcoin", "MVRV": 1.237767811543}]}, {"name": "chain_metrics", "type": null, "comment": 0, "row_count": 5541, "relevance_score": 2.0, "columns": [{"column_name": "price_usd", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 10.0}, {"column_name": "coin", "data_type": "character varying", "is_nullable": "NO", "column_default": null, "character_maximum_length": 255, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "time", "data_type": "date", "is_nullable": "NO", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "market_cap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "hash_rate", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "current_supply", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "active_address_count", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "transfer_count", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "realized_cap", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "mvrv", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "volatility_30d", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "volatility_180d", "data_type": "double precision", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 53, "numeric_scale": null, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"coin": "bitcoin", "time": "2022-05-05", "price_usd": 36502.0245601403, "market_cap": 694694154668.1462, "hash_rate": 232530821.92495468, "current_supply": 19031660.92948013, "active_address_count": 1189734, "transfer_count": 942304, "realized_cap": 465191628859.07263, "mvrv": 1.493350506698, "volatility_30d": 0.031144805184373972, "volatility_180d": 0.033436785910590884}, {"coin": "bitcoin", "time": "2024-03-31", "price_usd": 71227.4517939801, "market_cap": 1401014986716.4766, "hash_rate": 566120367.485718, "current_supply": 19669592.99300506, "active_address_count": 691124, "transfer_count": 752627, "realized_cap": 549531275361.9261, "mvrv": 2.54947270434, "volatility_30d": 0.03917722715181363, "volatility_180d": 0.027206757821629804}, {"coin": "bitcoin", "time": "2024-07-20", "price_usd": 67185.4978112215, "market_cap": 1325455815468.5513, "hash_rate": 672971424.2421774, "current_supply": 19728302.36657367, "active_address_count": 673407, "transfer_count": 1097203, "realized_cap": 613766368214.9689, "mvrv": 2.159544550027, "volatility_30d": 0.025340656522741825, "volatility_180d": 0.02763388661575242}]}, {"name": "p2p_trade_by_region", "type": null, "comment": 0, "row_count": 360, "relevance_score": 0.0, "columns": [{"column_name": "time", "data_type": "date", "is_nullable": "NO", "column_default": null, "character_maximum_length": null, "numeric_precision": null, "numeric_scale": null, "column_comment": null, "is_primary_key": true, "relevance_score": 2.0}, {"column_name": "eastern_europe", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "latin_america", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "north_america", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "western_europe", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "asia_pacific", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "sub_saharan_africa", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "aus_nz", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "middle_east_north_africa", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}, {"column_name": "sum_regions_btc_volume", "data_type": "bigint", "is_nullable": "YES", "column_default": null, "character_maximum_length": null, "numeric_precision": 64, "numeric_scale": 0, "column_comment": null, "is_primary_key": false, "relevance_score": 0.0}], "foreign_keys": [], "example_rows": [{"time": "2015-07-05", "eastern_europe": 635215, "latin_america": 118174, "north_america": 4126444, "western_europe": 2051156, "asia_pacific": 344566, "sub_saharan_africa": 196484, "aus_nz": 499609, "middle_east_north_africa": 11988, "sum_regions_btc_volume": 7983636}, {"time": "2015-07-12", "eastern_europe": 599789, "latin_america": 178807, "north_america": 4386854, "western_europe": 1796552, "asia_pacific": 323553, "sub_saharan_africa": 174492, "aus_nz": 496131, "middle_east_north_africa": 10845, "sum_regions_btc_volume": 7967023}, {"time": "2015-07-19", "eastern_europe": 571615, "latin_america": 113187, "north_america": 4396480, "western_europe": 1757334, "asia_pacific": 344669, "sub_saharan_africa": 246366, "aus_nz": 503517, "middle_east_north_africa": 12502, "sum_regions_btc_volume": 7945670}]}]
Task
Produce a concise, engine-aware schema context that a downstream model will use to translate natural-language requests into SQL.
Hard Requirements
Return ONLY the formatted schema context text. No explanations, no labels, no wrappers.
If raw_metadata is insufficient to generate a usable schema context, return exactly: I don't have enough data complete your request
Preserve exact table and column names and case; do not invent or rename any identifiers.
About raw_metadata (new format)
Each table object contains: name, type, comment, row_count, relevance_score, columns (with column_name, data_type, is_nullable, column_default, character_maximum_length, numeric_precision, numeric_scale, column_comment, is_primary_key, relevance_score), foreign_keys, and optional example_rows. Use example_rows only to inform relevance — do not emit them.
Formatting (produce in this exact order)
Engine Notes:
Identifier quoting rule for postgresql
Identifier case-sensitivity behavior for postgresql
Case-insensitive string-match guidance for postgresql
Date/time function hints for postgresql (current timestamp, truncation, casting)
Row-limiting syntax for postgresql
Tables (list in relevance order; prioritize tables/columns matching user_intent):
Table: <fully qualified name if present; otherwise plain name>
Columns: (order by column relevance_score or PK first)
<column_name> (<data_type> [LEN <character_maximum_length>] [PREC <numeric_precision>,<numeric_scale>] [DEFAULT <column_default>] [PK if true] [NULLABLE/NOT NULL])
Notes:
Columns requiring quoting (mixed-case / special chars)
Date/time columns and any type mismatches needing casts (e.g., DATE vs TIMESTAMP)
Composite PKs or implied uniqueness (if discernible)
Suggested Joins:
List obvious join keys where names and types align (e.g., chain_metrics.coin = market_data.coin; chain_metrics.time = market_data.time)
If date vs timestamp mismatch exists, show engine-specific CAST or date_trunc examples to align keys
Possible Synonyms:
List likely equivalent identifiers across tables (e.g., coin vs symbol) without renaming or enforcing joins
Constraints and Query Hints:
Primary-key composites or uniqueness implied by metadata
Columns commonly used for filtering/sorting (time, price, market_cap, etc.)
Remind that identifiers must match exactly and engine-specific quoting may be required
Engine Presets (emit only the preset matching engine_name; include but do not alter the following examples)
PostgreSQL:
Quoting: "identifier"
Case-insensitive match: ILIKE or LOWER(col)=LOWER('value')
Date/time: NOW(), CURRENT_DATE, date_trunc('day', ts), CAST/::, ::date
Limit: LIMIT n
MySQL:
Quoting: identifier
Case-insensitive match: default collations; otherwise LOWER(...)
Date/time: NOW(), CURDATE(), DATE_FORMAT, CAST/CONVERT
Limit: LIMIT n
SQL Server:
Quoting: [identifier] (or "identifier" with QUOTED_IDENTIFIER ON)
Case-insensitive match: depends on collation; otherwise LOWER(...)
Date/time: GETDATE(), SYSUTCDATETIME(), DATEADD, DATEDIFF, FORMAT, CAST/CONVERT
Limit: SELECT TOP n ...
Oracle:
Quoting: "identifier"
Case-insensitive match: LOWER(col)=LOWER('value') or NLSSORT/NLS_COMP
Date/time: SYSTIMESTAMP, TRUNC(date), CAST, TO_DATE/TO_TIMESTAMP
Limit: FETCH FIRST n ROWS ONLY or ROWNUM
Selection & Compression Rules
Use relevance_score and user_intent to order tables and columns.
Do NOT emit example_rows; they are only for internal relevance inference.
Validation
Never invent tables, columns, types, or foreign keys not present in raw_metadata.
Preserve schema prefixes if present.
Maintain exact case for all identifiers.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment