sql-data-guard 0.1.1__tar.gz → 0.1.3__tar.gz

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.
Files changed (27) hide show
  1. {sql_data_guard-0.1.1/src/sql_data_guard.egg-info → sql_data_guard-0.1.3}/PKG-INFO +5 -20
  2. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/README.md +4 -19
  3. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/pyproject.toml +1 -1
  4. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/restriction_verification.py +1 -1
  5. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/sql_data_guard.py +7 -3
  6. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3/src/sql_data_guard.egg-info}/PKG-INFO +5 -20
  7. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_sql_guard_unit.py +9 -3
  8. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/LICENSE.md +0 -0
  9. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/setup.cfg +0 -0
  10. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/__init__.py +0 -0
  11. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/rest/__init__.py +0 -0
  12. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/rest/sql_data_guard_rest.py +0 -0
  13. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/restriction_validation.py +0 -0
  14. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/verification_context.py +0 -0
  15. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard/verification_utils.py +0 -0
  16. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard.egg-info/SOURCES.txt +0 -0
  17. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard.egg-info/dependency_links.txt +0 -0
  18. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard.egg-info/requires.txt +0 -0
  19. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/src/sql_data_guard.egg-info/top_level.txt +0 -0
  20. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_duckdb_unit.py +0 -0
  21. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_rest_api_unit.py +0 -0
  22. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_sql_guard_curr_unit.py +0 -0
  23. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_sql_guard_joins_unit.py +0 -0
  24. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_sql_guard_llm.py +0 -0
  25. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_sql_guard_updates_unit.py +0 -0
  26. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_sql_guard_validation_unit.py +0 -0
  27. {sql_data_guard-0.1.1 → sql_data_guard-0.1.3}/test/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sql-data-guard
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Safety Layer for LLM Database Interactions
5
5
  Author-email: Imperva - Threat Reseach Infra <ww.dis.imperva.threat-research-infra@thalesgroup.com>
6
6
  License: MIT License
@@ -93,6 +93,9 @@ Output:
93
93
  "fixed": "SELECT id, product_name, account_id FROM orders WHERE account_id = 123"
94
94
  }
95
95
  ```
96
+ For more details on restriction rules and validation, see the [manual.](docs/manual.md)
97
+
98
+
96
99
  Here is a table with more examples of SQL queries and their corresponding JSON outputs:
97
100
 
98
101
  | SQL Query | JSON Output |
@@ -111,24 +114,6 @@ To install sql-data-guard, use pip:
111
114
  ```bash
112
115
  pip install sql-data-guard
113
116
  ```
114
- ## Restriction Schema and Validation
115
-
116
- Restrictions are used to validate queries by ensuring that only supported operations are applied to table columns. The `validate_restrictions` function enforces these rules, allowing only specific operations and ensuring correct formats.
117
- ## **Supported Operations**
118
- - `=` (Equal to)
119
- - `>` (Greater than)
120
- - `<` (Less than)
121
- - `>=` (Greater than or equal to)
122
- - `<=` (Less than or equal to)
123
- - `BETWEEN` (Range validation)
124
- - `IN` (List validation)
125
-
126
- ## **Example for Restriction**
127
- ```
128
- "column": "price",
129
- "operation": ">=",
130
- "value": 100
131
- ```
132
117
 
133
118
  ## Docker Repository
134
119
 
@@ -167,4 +152,4 @@ curl -X POST http://localhost:5000/verify-sql \
167
152
  We welcome contributions! Please see our [CONTRIBUTING.md](https://raw.githubusercontent.com/ThalesGroup/sql-data-guard/main/CONTRIBUTING.md) for more details.
168
153
 
169
154
  ## License
170
- This project is licensed under the MIT License. See the [LICENSE.md](LICENSE) file for details.
155
+ This project is licensed under the MIT License. See the [LICENSE.md](https://raw.githubusercontent.com/ThalesGroup/sql-data-guard/main/LICENSE.md) file for details.
@@ -69,6 +69,9 @@ Output:
69
69
  "fixed": "SELECT id, product_name, account_id FROM orders WHERE account_id = 123"
70
70
  }
71
71
  ```
72
+ For more details on restriction rules and validation, see the [manual.](docs/manual.md)
73
+
74
+
72
75
  Here is a table with more examples of SQL queries and their corresponding JSON outputs:
73
76
 
74
77
  | SQL Query | JSON Output |
@@ -87,24 +90,6 @@ To install sql-data-guard, use pip:
87
90
  ```bash
88
91
  pip install sql-data-guard
89
92
  ```
90
- ## Restriction Schema and Validation
91
-
92
- Restrictions are used to validate queries by ensuring that only supported operations are applied to table columns. The `validate_restrictions` function enforces these rules, allowing only specific operations and ensuring correct formats.
93
- ## **Supported Operations**
94
- - `=` (Equal to)
95
- - `>` (Greater than)
96
- - `<` (Less than)
97
- - `>=` (Greater than or equal to)
98
- - `<=` (Less than or equal to)
99
- - `BETWEEN` (Range validation)
100
- - `IN` (List validation)
101
-
102
- ## **Example for Restriction**
103
- ```
104
- "column": "price",
105
- "operation": ">=",
106
- "value": 100
107
- ```
108
93
 
109
94
  ## Docker Repository
110
95
 
@@ -143,4 +128,4 @@ curl -X POST http://localhost:5000/verify-sql \
143
128
  We welcome contributions! Please see our [CONTRIBUTING.md](https://raw.githubusercontent.com/ThalesGroup/sql-data-guard/main/CONTRIBUTING.md) for more details.
144
129
 
145
130
  ## License
146
- This project is licensed under the MIT License. See the [LICENSE.md](LICENSE) file for details.
131
+ This project is licensed under the MIT License. See the [LICENSE.md](https://raw.githubusercontent.com/ThalesGroup/sql-data-guard/main/LICENSE.md) file for details.
@@ -9,7 +9,7 @@ package-dir = {"" = "src"}
9
9
  extra-index-url = ["https://pypi.org/simple"]
10
10
  [project]
11
11
  name = "sql-data-guard"
12
- version = "0.1.1"
12
+ version = "0.1.3"
13
13
  dependencies = [
14
14
  "sqlglot"
15
15
  ]
@@ -70,7 +70,7 @@ def _create_new_condition(
70
70
  """
71
71
  if restriction.get("operation") == "BETWEEN":
72
72
  operator = "BETWEEN"
73
- operand = f"{_format_value(restriction["values"][0])} AND {_format_value(restriction["values"][1])}"
73
+ operand = f"{_format_value(restriction['values'][0])} AND {_format_value(restriction['values'][1])}"
74
74
  elif restriction.get("operation") == "IN":
75
75
  operator = "IN"
76
76
  values = restriction.get("values", [restriction.get("value")])
@@ -135,6 +135,10 @@ def _verify_query_statement(query_statement: expr.Query, context: VerificationCo
135
135
  for cte in query_statement.ctes:
136
136
  _add_table_alias(cte, context)
137
137
  _verify_query_statement(cte.this, context)
138
+ where_clause = query_statement.find(expr.Where)
139
+ if where_clause:
140
+ for sub in where_clause.find_all(expr.Subquery):
141
+ _verify_query_statement(sub.this, context)
138
142
  from_tables = _get_from_clause_tables(query_statement, context)
139
143
  for t in from_tables:
140
144
  found = False
@@ -251,8 +255,8 @@ def _get_from_clause_tables(
251
255
  """
252
256
  result = []
253
257
  from_clause = select_clause.find(expr.From)
254
- join_clause = select_clause.find(expr.Join)
255
- for clause in [from_clause, join_clause]:
258
+ join_clauses = select_clause.args.get("joins", [])
259
+ for clause in [from_clause] + join_clauses:
256
260
  if clause:
257
261
  for t in find_direct(clause, expr.Table):
258
262
  if isinstance(t, expr.Table):
@@ -260,7 +264,7 @@ def _get_from_clause_tables(
260
264
  for l in find_direct(clause, expr.Subquery):
261
265
  _add_table_alias(l, context)
262
266
  _verify_query_statement(l.this, context)
263
- if join_clause:
267
+ for join_clause in join_clauses:
264
268
  for l in find_direct(join_clause, expr.Lateral):
265
269
  _add_table_alias(l, context)
266
270
  _verify_query_statement(l.this.find(expr.Select), context)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sql-data-guard
3
- Version: 0.1.1
3
+ Version: 0.1.3
4
4
  Summary: Safety Layer for LLM Database Interactions
5
5
  Author-email: Imperva - Threat Reseach Infra <ww.dis.imperva.threat-research-infra@thalesgroup.com>
6
6
  License: MIT License
@@ -93,6 +93,9 @@ Output:
93
93
  "fixed": "SELECT id, product_name, account_id FROM orders WHERE account_id = 123"
94
94
  }
95
95
  ```
96
+ For more details on restriction rules and validation, see the [manual.](docs/manual.md)
97
+
98
+
96
99
  Here is a table with more examples of SQL queries and their corresponding JSON outputs:
97
100
 
98
101
  | SQL Query | JSON Output |
@@ -111,24 +114,6 @@ To install sql-data-guard, use pip:
111
114
  ```bash
112
115
  pip install sql-data-guard
113
116
  ```
114
- ## Restriction Schema and Validation
115
-
116
- Restrictions are used to validate queries by ensuring that only supported operations are applied to table columns. The `validate_restrictions` function enforces these rules, allowing only specific operations and ensuring correct formats.
117
- ## **Supported Operations**
118
- - `=` (Equal to)
119
- - `>` (Greater than)
120
- - `<` (Less than)
121
- - `>=` (Greater than or equal to)
122
- - `<=` (Less than or equal to)
123
- - `BETWEEN` (Range validation)
124
- - `IN` (List validation)
125
-
126
- ## **Example for Restriction**
127
- ```
128
- "column": "price",
129
- "operation": ">=",
130
- "value": 100
131
- ```
132
117
 
133
118
  ## Docker Repository
134
119
 
@@ -167,4 +152,4 @@ curl -X POST http://localhost:5000/verify-sql \
167
152
  We welcome contributions! Please see our [CONTRIBUTING.md](https://raw.githubusercontent.com/ThalesGroup/sql-data-guard/main/CONTRIBUTING.md) for more details.
168
153
 
169
154
  ## License
170
- This project is licensed under the MIT License. See the [LICENSE.md](LICENSE) file for details.
155
+ This project is licensed under the MIT License. See the [LICENSE.md](https://raw.githubusercontent.com/ThalesGroup/sql-data-guard/main/LICENSE.md) file for details.
@@ -252,6 +252,7 @@ INSERT INTO orders (order_id, account_id, product_id) VALUES
252
252
  COUNT(o.order_id) AS order_count
253
253
  FROM orders o
254
254
  JOIN products p ON o.product_id = p.product_id
255
+ WHERE o.account_id = 123
255
256
  GROUP BY o.account_id, p.product_name
256
257
  ),
257
258
  RankedProducts AS (
@@ -273,11 +274,16 @@ FROM OrderCounts oc
273
274
  JOIN RankedProducts rp ON oc.product_name = rp.product_name
274
275
  WHERE oc.account_id IN (
275
276
  -- Filter accounts with at least 2 orders
276
- SELECT account_id FROM orders GROUP BY account_id HAVING COUNT(order_id) >= 2
277
+ SELECT account_id FROM orders
278
+ WHERE account_id = 123
279
+ GROUP BY account_id HAVING COUNT(order_id) >= 2
277
280
  )
278
281
  ORDER BY oc.account_id, rp.product_rank;"""
279
- verify_sql_test_data(
280
- sql, config, cnn, [(123, "Laptop", 1, 1), (123, "Smartphone", 1, 1)]
282
+ verify_sql_test(
283
+ sql,
284
+ config,
285
+ cnn=cnn,
286
+ data=[(123, "Laptop", 1, 1), (123, "Smartphone", 1, 1)],
281
287
  )
282
288
 
283
289
 
File without changes