text2sql-engine 0.1.1__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
text2sql/__init__.py CHANGED
@@ -37,7 +37,7 @@ from .types import (
37
37
  TokenUsage,
38
38
  )
39
39
 
40
- __version__ = "0.1.1"
40
+ __version__ = "0.2.0"
41
41
 
42
42
  __all__ = [
43
43
  "Text2SQL",
@@ -82,6 +82,19 @@ class GenerationStage:
82
82
  reduced_schema = full_schema.subset(linked.tables)
83
83
  reduced_text = schema_to_prompt(reduced_schema) if reduced_schema.tables else "(none)"
84
84
 
85
+ # Forward Stage 1's reasoning to Stage 2. The linking model already
86
+ # worked out the logic (ranges, joins, which column means what); the SQL
87
+ # model should follow it instead of guessing.
88
+ columns_text = "\n".join(
89
+ f"- {c.table}.{c.column}" + (f" — {c.reason}" if c.reason else "")
90
+ for c in linked.columns
91
+ ) or "(none)"
92
+ joins_text = "\n".join(
93
+ f"- {j.left_table}.{j.left_column} = {j.right_table}.{j.right_column}"
94
+ for j in linked.joins
95
+ ) or "(none)"
96
+ rationale_text = linked.rationale.strip() or "(none)"
97
+
85
98
  template = self._prompts.load(stage_cfg.prompt_template)
86
99
  system, user = template.render(
87
100
  linked_schema=reduced_text,
@@ -89,6 +102,9 @@ class GenerationStage:
89
102
  dialect=self._settings.general.sql_dialect,
90
103
  entities=", ".join(linked.entities) or "(none)",
91
104
  filters="; ".join(linked.filters) or "(none)",
105
+ columns=columns_text,
106
+ joins=joins_text,
107
+ rationale=rationale_text,
92
108
  )
93
109
 
94
110
  attempts = {"n": 0}
@@ -1,12 +1,17 @@
1
1
  SYSTEM:
2
- You are an expert SQL generator. You get a user request and a reduced schema
3
- (only the relevant tables/columns/joins picked by an upstream linking step).
4
- Produce one correct SQL query in the target dialect.
2
+ You are an expert SQL generator. You get a user request, a reduced schema (only
3
+ the relevant tables/columns/joins picked by an upstream linking step), and that
4
+ step's analysis. Produce one correct SQL query in the target dialect.
5
5
 
6
6
  Rules:
7
7
  - Use only the tables and columns in the reduced schema.
8
+ - Follow the linking analysis. It already worked out the logic; do not ignore it.
9
+ - Respect the intended comparison semantics from the analysis and filter hints.
10
+ If a value should be matched by a numeric range or an exact compare, implement
11
+ it that way. Do not fall back to substring/text (LIKE) matching unless that is
12
+ clearly what is meant.
13
+ - Use the suggested joins to connect tables. Prefer explicit JOINs.
8
14
  - Write idiomatic SQL for the target dialect: {dialect}.
9
- - Prefer explicit JOINs using the given relations.
10
15
  - Do not run the query. Only produce it.
11
16
  - Return the answer strictly as the requested JSON object with two fields:
12
17
  "sql" (the query) and "explanation" (one or two sentences).
@@ -19,6 +24,15 @@ Reduced schema (relevant subset):
19
24
  {linked_schema}
20
25
  --------------------------------
21
26
 
27
+ Linking analysis (reasoning from the previous step — follow this logic):
28
+ {rationale}
29
+
30
+ Relevant columns:
31
+ {columns}
32
+
33
+ Suggested joins:
34
+ {joins}
35
+
22
36
  Detected entities: {entities}
23
37
  Filter hints: {filters}
24
38
 
@@ -1,12 +1,17 @@
1
1
  SYSTEM:
2
- You are an expert SQL generator. You get a user request and a reduced schema
3
- (only the relevant tables/columns/joins picked by an upstream linking step).
4
- Produce one correct SQL query in the target dialect.
2
+ You are an expert SQL generator. You get a user request, a reduced schema (only
3
+ the relevant tables/columns/joins picked by an upstream linking step), and that
4
+ step's analysis. Produce one correct SQL query in the target dialect.
5
5
 
6
6
  Rules:
7
7
  - Use only the tables and columns in the reduced schema.
8
+ - Follow the linking analysis. It already worked out the logic; do not ignore it.
9
+ - Respect the intended comparison semantics from the analysis and filter hints.
10
+ If a value should be matched by a numeric range or an exact compare, implement
11
+ it that way. Do not fall back to substring/text (LIKE) matching unless that is
12
+ clearly what is meant.
13
+ - Use the suggested joins to connect tables. Prefer explicit JOINs.
8
14
  - Write idiomatic SQL for the target dialect: {dialect}.
9
- - Prefer explicit JOINs using the given relations.
10
15
  - Do not run the query. Only produce it.
11
16
  - Output ONLY the SQL query. No explanation, no comment, no markdown fences.
12
17
 
@@ -18,6 +23,15 @@ Reduced schema (relevant subset):
18
23
  {linked_schema}
19
24
  --------------------------------
20
25
 
26
+ Linking analysis (reasoning from the previous step — follow this logic):
27
+ {rationale}
28
+
29
+ Relevant columns:
30
+ {columns}
31
+
32
+ Suggested joins:
33
+ {joins}
34
+
21
35
  Detected entities: {entities}
22
36
  Filter hints: {filters}
23
37
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: text2sql-engine
3
- Version: 0.1.1
3
+ Version: 0.2.0
4
4
  Summary: Schema-agnostic, config-driven Text-to-SQL library (2-stage LLM pipeline). Produces a SQL string; never connects to or executes against a database.
5
5
  Author: Mehmet Kaan Durupunar
6
6
  License: MIT
@@ -70,8 +70,9 @@ user request
70
70
  reduces the schema to the relevant part and returns structured JSON. Output is
71
71
  forced via `response_format` (OpenAI) or tool-calling (Anthropic), with
72
72
  strict-JSON parsing and retry as a fallback.
73
- - **Stage 2 (generation)** takes the request and that reduced subset. It writes
74
- SQL in the target dialect. Two output modes (config `output_mode`):
73
+ - **Stage 2 (generation)** takes the request, that reduced subset, and Stage 1's
74
+ reasoning (rationale, chosen joins, column reasons). It follows that logic and
75
+ writes SQL in the target dialect. Two output modes (config `output_mode`):
75
76
  `structured` forces JSON with `sql` + `explanation`; `raw` asks for plain SQL
76
77
  text, for specialized text-to-SQL models.
77
78
  - The two stages can use **different providers and models**. For example a cheap
@@ -1,17 +1,17 @@
1
- text2sql/__init__.py,sha256=oMYRHWUUR6cRjpG0EAMdmDAPF82UCPbMEd4lyRx_4Sc,1442
1
+ text2sql/__init__.py,sha256=dwQ98mfnAHRbUhKmOEnC0BcGK-8Slxosi8hqDgpkheM,1442
2
2
  text2sql/config.py,sha256=6snv99rf8jf8NtD3xetSrvIaltbLyq2eoISoMoPadSw,8503
3
3
  text2sql/errors.py,sha256=Y5ORy7g_UsFvDJ2KorB2JFvTyOBqmrPv9MWc8Cl9MI8,1052
4
4
  text2sql/logging_utils.py,sha256=hiEH1SDqP16kctUj4uPP0tbXdrCO9AlRcdS-mHYDg5s,1633
5
5
  text2sql/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  text2sql/types.py,sha256=MxcdHP7Gnftk1yKdcBQKaVVyeqRnBu5kxbhSZ2xJJ80,3532
7
7
  text2sql/pipeline/__init__.py,sha256=rjEOi4U9C-SKP15cyKPdvG_EZBOW0VW01LouS3PJVdY,245
8
- text2sql/pipeline/generation.py,sha256=rXzU6e4LyyPTlHSkqT4IsZA-Xf-DjK3Kp9QAbpA2PJ4,5030
8
+ text2sql/pipeline/generation.py,sha256=M9wehTcMAq1QoK1nnQ4SJd1mszSfXs9E06l26IXpKNw,5750
9
9
  text2sql/pipeline/json_utils.py,sha256=92viA3xyw_GMF_nKdjSPgAyQ8iBUZgnyNRAoyWC5ZlE,3145
10
10
  text2sql/pipeline/linking.py,sha256=U28LOcWJn3cItwAsv2fG4fYv9KcJ80XmP1Fi8nNx4qc,6966
11
11
  text2sql/pipeline/pipeline.py,sha256=TE0cHSEJyeY43P89HsQDbnPGSfgRQmtw7KZAq-Yjj1U,5675
12
12
  text2sql/prompts/__init__.py,sha256=HfeflfAGsZl3xHnNrmklTP6K_8EKxX6vWJrayq6QuEQ,3315
13
- text2sql/prompts/generation.txt,sha256=r4125WCr7gsJIzTa5wZTAmbTyn5WvP3QrfGf4CWNP_w,849
14
- text2sql/prompts/generation_raw.txt,sha256=wAvUvHd2Qywfy-Poc-7lqW5Gmg1nf3IyFDwtZNBCJls,789
13
+ text2sql/prompts/generation.txt,sha256=th97BZsHFlRtH30OqHj4DY_BooCsa7Zad9EoXC9M_cM,1381
14
+ text2sql/prompts/generation_raw.txt,sha256=EsKLl7WrNWQzcoxAFW9l6yucUtBa7sIimCsvIjRx7ZI,1321
15
15
  text2sql/prompts/linking.txt,sha256=nLPSkaq3PiWiJ7wXLeD0BvK_-rR3hhc_tLhZ-daPnGY,889
16
16
  text2sql/providers/__init__.py,sha256=R5a-YKtyaUFpkVJGWrmhDGyRHeh84gA3F7nEH57dSGo,345
17
17
  text2sql/providers/anthropic_provider.py,sha256=Zhh8zM6EfHqkjTgNmhYKdZLHQ69b0Pu2-5WbCW2rD6s,4342
@@ -23,8 +23,8 @@ text2sql/schema/file_provider.py,sha256=Nv9x2-Eh9mXISk5XvUQaLfagth2s3LbX5F7jWp-o
23
23
  text2sql/schema/models.py,sha256=yX5zdKbTuy-g-nkwT0v-0HUTK81jBRoabV-OC-kD-JI,2263
24
24
  text2sql/schema/provider.py,sha256=JPMRsjRgEB4RdQR_pFwbP2LwLIXZhQVWSQPoYzaXC7s,798
25
25
  text2sql/schema/serialize.py,sha256=_2MeA1IwDJ51-69PXyqXBSFZSyzovbqJkRIMpekkfJA,1833
26
- text2sql_engine-0.1.1.dist-info/licenses/LICENSE,sha256=qfdfVnpb5NOM3-SK13PnmWagjCLy5sE9ORlgOGXc8hU,1078
27
- text2sql_engine-0.1.1.dist-info/METADATA,sha256=ixiIwDgwu2F0KvULAh2niQSs-OW_dI7faEMGC4hgfb4,12971
28
- text2sql_engine-0.1.1.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
29
- text2sql_engine-0.1.1.dist-info/top_level.txt,sha256=ZONWO1r8wsWpyHhF5qPzAjnsNoCEhwZ2Z-M_V8nKALc,9
30
- text2sql_engine-0.1.1.dist-info/RECORD,,
26
+ text2sql_engine-0.2.0.dist-info/licenses/LICENSE,sha256=qfdfVnpb5NOM3-SK13PnmWagjCLy5sE9ORlgOGXc8hU,1078
27
+ text2sql_engine-0.2.0.dist-info/METADATA,sha256=Xn9bMUbUlTrirl1JWpZ99bOrfZRZzK2IdDx8bQVmRFw,13061
28
+ text2sql_engine-0.2.0.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
29
+ text2sql_engine-0.2.0.dist-info/top_level.txt,sha256=ZONWO1r8wsWpyHhF5qPzAjnsNoCEhwZ2Z-M_V8nKALc,9
30
+ text2sql_engine-0.2.0.dist-info/RECORD,,