@memberjunction/db-auto-doc 4.0.0 → 4.2.0
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.
- package/README.md +58 -26
- package/dist/commands/generate-queries.d.ts.map +1 -1
- package/dist/commands/generate-queries.js +3 -0
- package/dist/commands/generate-queries.js.map +1 -1
- package/dist/core/AnalysisOrchestrator.d.ts.map +1 -1
- package/dist/core/AnalysisOrchestrator.js +18 -2
- package/dist/core/AnalysisOrchestrator.js.map +1 -1
- package/dist/database/Database.d.ts.map +1 -1
- package/dist/database/Database.js +32 -20
- package/dist/database/Database.js.map +1 -1
- package/dist/drivers/SQLServerDriver.d.ts.map +1 -1
- package/dist/drivers/SQLServerDriver.js +20 -13
- package/dist/drivers/SQLServerDriver.js.map +1 -1
- package/dist/prompts/PromptEngine.d.ts.map +1 -1
- package/dist/prompts/PromptEngine.js +17 -17
- package/dist/prompts/PromptEngine.js.map +1 -1
- package/dist/prompts/PromptFileLoader.d.ts +1 -1
- package/dist/prompts/PromptFileLoader.d.ts.map +1 -1
- package/dist/prompts/PromptFileLoader.js +1 -1
- package/dist/prompts/PromptFileLoader.js.map +1 -1
- package/package.json +7 -6
- package/prompts/backpropagation.md +55 -0
- package/prompts/convergence-check.md +79 -0
- package/prompts/cross-schema-check.md +61 -0
- package/prompts/cross-schema-sanity-check.md +133 -0
- package/prompts/dependency-level-sanity-check.md +92 -0
- package/prompts/query-fix.md +141 -0
- package/prompts/query-planning.md +144 -0
- package/prompts/query-refinement.md +151 -0
- package/prompts/schema-level-sanity-check.md +114 -0
- package/prompts/schema-sanity-check.md +54 -0
- package/prompts/semantic-comparison.md +78 -0
- package/prompts/single-query-generation.md +155 -0
- package/prompts/table-analysis.md +139 -0
- package/dist/ai/simple-ai-client.d.ts +0 -70
- package/dist/ai/simple-ai-client.d.ts.map +0 -1
- package/dist/ai/simple-ai-client.js +0 -181
- package/dist/ai/simple-ai-client.js.map +0 -1
- package/dist/analyzers/analyzer.d.ts +0 -23
- package/dist/analyzers/analyzer.d.ts.map +0 -1
- package/dist/analyzers/analyzer.js +0 -127
- package/dist/analyzers/analyzer.js.map +0 -1
- package/dist/cli-old/cli.d.ts +0 -3
- package/dist/cli-old/cli.d.ts.map +0 -1
- package/dist/cli-old/cli.js +0 -388
- package/dist/cli-old/cli.js.map +0 -1
- package/dist/commands/review.d.ts +0 -11
- package/dist/commands/review.d.ts.map +0 -1
- package/dist/commands/review.js +0 -82
- package/dist/commands/review.js.map +0 -1
- package/dist/database/connection.d.ts +0 -40
- package/dist/database/connection.d.ts.map +0 -1
- package/dist/database/connection.js +0 -136
- package/dist/database/connection.js.map +0 -1
- package/dist/database/introspection.d.ts +0 -59
- package/dist/database/introspection.d.ts.map +0 -1
- package/dist/database/introspection.js +0 -124
- package/dist/database/introspection.js.map +0 -1
- package/dist/generators/markdown-generator.d.ts +0 -8
- package/dist/generators/markdown-generator.d.ts.map +0 -1
- package/dist/generators/markdown-generator.js +0 -106
- package/dist/generators/markdown-generator.js.map +0 -1
- package/dist/generators/sql-generator.d.ts +0 -20
- package/dist/generators/sql-generator.d.ts.map +0 -1
- package/dist/generators/sql-generator.js +0 -83
- package/dist/generators/sql-generator.js.map +0 -1
- package/dist/state/state-manager.d.ts +0 -95
- package/dist/state/state-manager.d.ts.map +0 -1
- package/dist/state/state-manager.js +0 -236
- package/dist/state/state-manager.js.map +0 -1
- package/dist/types/state-file.d.ts +0 -124
- package/dist/types/state-file.d.ts.map +0 -1
- package/dist/types/state-file.js +0 -79
- package/dist/types/state-file.js.map +0 -1
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Query Planning for Database Documentation
|
|
2
|
+
|
|
3
|
+
You are designing a set of reference SQL queries for the **{{ focusTable }}** table in the **{{ schemaName }}** schema. These queries will serve as examples for AI agents and developers.
|
|
4
|
+
|
|
5
|
+
## Database Context
|
|
6
|
+
|
|
7
|
+
**Database Type:** {{ databaseType }}
|
|
8
|
+
|
|
9
|
+
**Focus Table:** {{ focusTable }}
|
|
10
|
+
{{ tables[0].description }}
|
|
11
|
+
|
|
12
|
+
**Row Count:** {{ tables[0].rowCount }}
|
|
13
|
+
|
|
14
|
+
### Columns
|
|
15
|
+
{% for col in tables[0].columns %}
|
|
16
|
+
- **{{ col.name }}** ({{ col.dataType }}){% if col.isPrimaryKey %} [PRIMARY KEY]{% endif %}{% if col.isForeignKey %} [FOREIGN KEY]{% endif %}
|
|
17
|
+
{% if col.description %}{{ col.description }}{% endif %}
|
|
18
|
+
{% if col.possibleValues %}Possible values: {{ col.possibleValues | jsoninline }}{% endif %}
|
|
19
|
+
{% endfor %}
|
|
20
|
+
|
|
21
|
+
### Relationships
|
|
22
|
+
{% if tables[0].foreignKeys.length > 0 %}
|
|
23
|
+
**Foreign Keys:**
|
|
24
|
+
{% for fk in tables[0].foreignKeys %}
|
|
25
|
+
- {{ fk.column }} → {{ fk.referencesTable }}.{{ fk.referencesColumn }}
|
|
26
|
+
{% endfor %}
|
|
27
|
+
{% endif %}
|
|
28
|
+
|
|
29
|
+
{% if tables[0].dependents.length > 0 %}
|
|
30
|
+
**Referenced By:** {{ tables[0].dependents | join(', ') }}
|
|
31
|
+
{% endif %}
|
|
32
|
+
|
|
33
|
+
{% if tables.length > 1 %}
|
|
34
|
+
### Related Tables Available
|
|
35
|
+
{% for table in tables | slice(1) %}
|
|
36
|
+
- **{{ table.name }}** ({{ table.rowCount }} rows){% if table.description %}: {{ table.description }}{% endif %}
|
|
37
|
+
{% endfor %}
|
|
38
|
+
{% endif %}
|
|
39
|
+
|
|
40
|
+
{% if seedContext %}
|
|
41
|
+
## Database Purpose
|
|
42
|
+
{{ seedContext }}
|
|
43
|
+
{% endif %}
|
|
44
|
+
|
|
45
|
+
{% if existingQueries.length > 0 %}
|
|
46
|
+
## Already Planned Queries
|
|
47
|
+
Avoid duplicating these query patterns:
|
|
48
|
+
{% for q in existingQueries %}
|
|
49
|
+
- {{ q.name }} ({{ q.queryType }}, {{ q.queryPattern }})
|
|
50
|
+
{% endfor %}
|
|
51
|
+
{% endif %}
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Task
|
|
56
|
+
|
|
57
|
+
Plan **{{ queriesPerTable }}** diverse, high-quality reference queries for the {{ focusTable }} table. Each query should demonstrate different patterns and business use cases.
|
|
58
|
+
|
|
59
|
+
### Query Types to Consider
|
|
60
|
+
- **aggregation**: GROUP BY with counts/sums/averages
|
|
61
|
+
- **filter**: SELECT with WHERE clauses
|
|
62
|
+
- **join**: Queries with related tables
|
|
63
|
+
- **detail**: Detailed record views
|
|
64
|
+
- **summary**: High-level aggregations
|
|
65
|
+
- **ranking**: TOP N / ORDER BY queries
|
|
66
|
+
- **time-series**: Date-based aggregations (if date columns exist)
|
|
67
|
+
- **drill-down**: Detail queries that support summary aggregations
|
|
68
|
+
|
|
69
|
+
### Query Patterns to Use
|
|
70
|
+
- simple-select
|
|
71
|
+
- filtered-select
|
|
72
|
+
- aggregation-group-by
|
|
73
|
+
- time-series-aggregation (if date columns available)
|
|
74
|
+
- join-detail
|
|
75
|
+
- left-join-counts
|
|
76
|
+
- drill-down-detail
|
|
77
|
+
- ranking-top-n
|
|
78
|
+
- multi-level-aggregation
|
|
79
|
+
|
|
80
|
+
### Complexity Distribution
|
|
81
|
+
- 40% simple: Basic SELECTs, single-table queries
|
|
82
|
+
- 40% moderate: JOINs, GROUP BY, basic aggregations
|
|
83
|
+
- 20% complex: Multi-table JOINs, nested aggregations, complex filtering
|
|
84
|
+
|
|
85
|
+
### Requirements
|
|
86
|
+
1. **Diversity**: Each query should demonstrate a different pattern or use case
|
|
87
|
+
2. **Business Value**: Focus on real-world business questions
|
|
88
|
+
3. **Alignment**: If creating summary + detail pairs, note their relationship in `relatedQueryIds`
|
|
89
|
+
4. **Realistic**: Queries should reflect actual data analysis needs
|
|
90
|
+
5. **Progressive Complexity**: Start simple, build to more complex patterns
|
|
91
|
+
|
|
92
|
+
### Multi-Query Alignment
|
|
93
|
+
When planning related queries (e.g., summary + drill-down detail):
|
|
94
|
+
- Use `relatedQueryIds` to link them
|
|
95
|
+
- Ensure they use **consistent filtering logic**
|
|
96
|
+
- Plan alignment notes for implementation phase
|
|
97
|
+
|
|
98
|
+
Example alignment issue to AVOID:
|
|
99
|
+
- Summary: "COUNT(*) FROM Registrations" (counts ALL)
|
|
100
|
+
- Detail: "SELECT * FROM Registrations WHERE Status='Attended'" (filters by status)
|
|
101
|
+
- ❌ Numbers won't match - bad user experience
|
|
102
|
+
|
|
103
|
+
Correct approach:
|
|
104
|
+
- Summary: "COUNT(*) FROM Registrations WHERE Status='Attended'"
|
|
105
|
+
- Detail: "SELECT * FROM Registrations WHERE Status='Attended'"
|
|
106
|
+
- ✅ Aligned filtering = numbers match
|
|
107
|
+
|
|
108
|
+
---
|
|
109
|
+
|
|
110
|
+
## Output Format
|
|
111
|
+
|
|
112
|
+
Return a JSON object with this structure:
|
|
113
|
+
|
|
114
|
+
```json
|
|
115
|
+
{
|
|
116
|
+
"queries": [
|
|
117
|
+
{
|
|
118
|
+
"id": "unique-id-1",
|
|
119
|
+
"name": "Clear, Descriptive Query Name",
|
|
120
|
+
"description": "What this query does and returns",
|
|
121
|
+
"businessPurpose": "Why someone would run this query - what business question it answers",
|
|
122
|
+
"queryType": "aggregation|filter|join|detail|summary|ranking|time-series|drill-down",
|
|
123
|
+
"queryPattern": "simple-select|filtered-select|aggregation-group-by|time-series-aggregation|join-detail|left-join-counts|drill-down-detail|ranking-top-n|multi-level-aggregation",
|
|
124
|
+
"complexity": "simple|moderate|complex",
|
|
125
|
+
"primaryEntities": [
|
|
126
|
+
{"schema": "{{ schemaName }}", "table": "{{ focusTable }}", "alias": "main"}
|
|
127
|
+
],
|
|
128
|
+
"relatedEntities": [
|
|
129
|
+
{"schema": "{{ schemaName }}", "table": "RelatedTable", "alias": "rel"}
|
|
130
|
+
],
|
|
131
|
+
"relatedQueryIds": ["unique-id-2"],
|
|
132
|
+
"confidence": 0.95,
|
|
133
|
+
"reasoning": "Why this query is valuable and how it differs from others"
|
|
134
|
+
}
|
|
135
|
+
]
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
**IMPORTANT:**
|
|
140
|
+
- Generate exactly {{ queriesPerTable }} diverse queries
|
|
141
|
+
- Ensure variety in queryType and queryPattern
|
|
142
|
+
- Link related queries via relatedQueryIds for alignment tracking
|
|
143
|
+
- All output must be valid, parseable JSON
|
|
144
|
+
- Use realistic business terminology from the domain
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# Refine SQL Query Based on Results
|
|
2
|
+
|
|
3
|
+
You are reviewing the results of a SQL query to determine if it correctly fulfills its intended business purpose. Analyze the sample results and suggest improvements if needed.
|
|
4
|
+
|
|
5
|
+
## Query Information
|
|
6
|
+
|
|
7
|
+
**Query ID:** {{ queryPlan.id }}
|
|
8
|
+
**Name:** {{ queryPlan.name }}
|
|
9
|
+
**Description:** {{ queryPlan.description }}
|
|
10
|
+
**Business Purpose:** {{ queryPlan.businessPurpose }}
|
|
11
|
+
**Type:** {{ queryPlan.queryType }}
|
|
12
|
+
**Pattern:** {{ queryPlan.queryPattern }}
|
|
13
|
+
|
|
14
|
+
## Database Context
|
|
15
|
+
|
|
16
|
+
**Database Type:** {{ databaseType }}
|
|
17
|
+
**Schema:** {{ schemaName }}
|
|
18
|
+
|
|
19
|
+
### Primary Table: {{ focusTable }}
|
|
20
|
+
{{ tableInfo.description }}
|
|
21
|
+
|
|
22
|
+
**Columns:**
|
|
23
|
+
{% for col in tableInfo.columns %}
|
|
24
|
+
- **{{ col.name }}** ({{ col.dataType }}){% if col.isPrimaryKey %} [PK]{% endif %}{% if col.isForeignKey %} [FK → {{ col.foreignKeyReferences.referencesTable }}]{% endif %}
|
|
25
|
+
{% if col.description %}{{ col.description }}{% endif %}
|
|
26
|
+
{% if col.possibleValues %}Values: {{ col.possibleValues | jsoninline }}{% endif %}
|
|
27
|
+
{% endfor %}
|
|
28
|
+
|
|
29
|
+
{% if relatedTables.length > 0 %}
|
|
30
|
+
### Related Tables
|
|
31
|
+
{% for table in relatedTables %}
|
|
32
|
+
**{{ table.name }}** ({{ table.rowCount }} rows)
|
|
33
|
+
{% if table.description %}{{ table.description }}{% endif %}
|
|
34
|
+
|
|
35
|
+
Columns:
|
|
36
|
+
{% for col in table.columns %}
|
|
37
|
+
- {{ col.name }} ({{ col.dataType }}){% if col.isPrimaryKey %} [PK]{% endif %}
|
|
38
|
+
{% endfor %}
|
|
39
|
+
|
|
40
|
+
{% endfor %}
|
|
41
|
+
{% endif %}
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## Current Query
|
|
46
|
+
|
|
47
|
+
### SQL
|
|
48
|
+
```sql
|
|
49
|
+
{{ currentSQL }}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### Parameters
|
|
53
|
+
{% for param in parameters %}
|
|
54
|
+
- **@{{ param.name }}** ({{ param.dataType }}): {{ param.description }}
|
|
55
|
+
{% endfor %}
|
|
56
|
+
|
|
57
|
+
### Expected Result Columns
|
|
58
|
+
{% for col in sampleResultColumns %}
|
|
59
|
+
- **{{ col.name }}** ({{ col.dataType }}): {{ col.description }}{% if col.isMeasure %} [Measure]{% endif %}{% if col.isDimension %} [Dimension]{% endif %}
|
|
60
|
+
{% endfor %}
|
|
61
|
+
|
|
62
|
+
---
|
|
63
|
+
|
|
64
|
+
## Sample Results
|
|
65
|
+
|
|
66
|
+
The query returned **{{ totalRows }} rows**. Here are {{ sampleRows.length }} sample rows:
|
|
67
|
+
|
|
68
|
+
{% if sampleRows.length > 0 %}
|
|
69
|
+
| {% for col in resultColumnNames %}{{ col }} | {% endfor %}
|
|
70
|
+
| {% for col in resultColumnNames %}--- | {% endfor %}
|
|
71
|
+
{% for row in sampleRows %}
|
|
72
|
+
| {% for col in resultColumnNames %}{{ row[col] }} | {% endfor %}
|
|
73
|
+
{% endfor %}
|
|
74
|
+
{% else %}
|
|
75
|
+
*No rows returned*
|
|
76
|
+
{% endif %}
|
|
77
|
+
|
|
78
|
+
{% if refinementNumber > 1 %}
|
|
79
|
+
### Previous Refinement Attempts
|
|
80
|
+
This is refinement attempt {{ refinementNumber }} of {{ maxRefinements }}.
|
|
81
|
+
|
|
82
|
+
{% for attempt in previousRefinements %}
|
|
83
|
+
**Attempt {{ loop.index }}:**
|
|
84
|
+
Feedback: {{ attempt.feedback }}
|
|
85
|
+
{% endfor %}
|
|
86
|
+
{% endif %}
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Task
|
|
91
|
+
|
|
92
|
+
Analyze the sample results and determine if the query correctly fulfills its business purpose.
|
|
93
|
+
|
|
94
|
+
### Questions to Consider
|
|
95
|
+
|
|
96
|
+
1. **Data Completeness**: Are we getting the expected columns and data? Are any important fields missing?
|
|
97
|
+
|
|
98
|
+
2. **Filter Correctness**: Do the results match the intended filters? For example:
|
|
99
|
+
- If filtering by "Active" status, do all rows show "Active"?
|
|
100
|
+
- If filtering by date range, are dates within the expected range?
|
|
101
|
+
|
|
102
|
+
3. **Aggregation Accuracy**: If this is an aggregation query:
|
|
103
|
+
- Do the counts/sums/averages seem reasonable?
|
|
104
|
+
- Is the grouping correct?
|
|
105
|
+
|
|
106
|
+
4. **Join Behavior**: Are we including or excluding records correctly?
|
|
107
|
+
- Are there unexpected NULL values from missing joins?
|
|
108
|
+
- Are we over-filtering by using INNER JOIN instead of LEFT JOIN?
|
|
109
|
+
|
|
110
|
+
5. **Business Logic**: Does the data make sense for the stated business purpose?
|
|
111
|
+
- Any unexpected patterns or outliers?
|
|
112
|
+
- Any values that shouldn't appear based on the query intent?
|
|
113
|
+
|
|
114
|
+
### Decision
|
|
115
|
+
|
|
116
|
+
Based on your analysis, decide one of the following:
|
|
117
|
+
|
|
118
|
+
1. **KEEP** - The query is correct and results match the business purpose
|
|
119
|
+
2. **REFINE** - The query needs improvements to better match the business purpose
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## Output Format
|
|
124
|
+
|
|
125
|
+
Return a JSON object:
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
{
|
|
129
|
+
"decision": "KEEP" | "REFINE",
|
|
130
|
+
"analysis": "Brief analysis of the results and why they do or don't match the business purpose",
|
|
131
|
+
"issues": [
|
|
132
|
+
"List of specific issues found (if any)"
|
|
133
|
+
],
|
|
134
|
+
"refinedQuery": {
|
|
135
|
+
"sqlQuery": "SELECT ... (only if decision is REFINE)",
|
|
136
|
+
"parameters": [...],
|
|
137
|
+
"sampleResultColumns": [...],
|
|
138
|
+
"filteringRules": [...],
|
|
139
|
+
"aggregationRules": [...],
|
|
140
|
+
"joinRules": [...],
|
|
141
|
+
"alignmentNotes": "..."
|
|
142
|
+
},
|
|
143
|
+
"refinementExplanation": "What was changed and why (only if decision is REFINE)"
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
**IMPORTANT:**
|
|
148
|
+
- Only provide `refinedQuery` if decision is "REFINE"
|
|
149
|
+
- The refined SQL must be valid and executable against {{ databaseType }}
|
|
150
|
+
- Preserve the original business purpose - don't change what the query is meant to do
|
|
151
|
+
- Focus on correctness, not optimization
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
You are reviewing an entire database schema to ensure all table descriptions are coherent, consistent, and logically sound when considered together as a complete system.
|
|
2
|
+
|
|
3
|
+
## Schema: {{ schemaName }}
|
|
4
|
+
|
|
5
|
+
Total tables: {{ tableCount }}
|
|
6
|
+
|
|
7
|
+
### Schema Description
|
|
8
|
+
{{ schemaDescription }}
|
|
9
|
+
|
|
10
|
+
### All Tables in Schema
|
|
11
|
+
|
|
12
|
+
{% for table in tables %}
|
|
13
|
+
#### {{ table.name }}
|
|
14
|
+
|
|
15
|
+
**Dependency Level**: {{ table.dependencyLevel }}
|
|
16
|
+
**Row Count**: {{ table.rowCount }}
|
|
17
|
+
|
|
18
|
+
**Description**: {{ table.description }}
|
|
19
|
+
|
|
20
|
+
**Key Columns**:
|
|
21
|
+
{% for column in table.keyColumns %}
|
|
22
|
+
- **{{ column.name }}** ({{ column.dataType }}): {{ column.description }}
|
|
23
|
+
{% endfor %}
|
|
24
|
+
|
|
25
|
+
**Relationships**:
|
|
26
|
+
- Depends On: {% for dep in table.dependsOn %}{{ dep.table }}{% if not loop.last %}, {% endif %}{% endfor %}
|
|
27
|
+
- Referenced By: {% for dep in table.dependents %}{{ dep.table }}{% if not loop.last %}, {% endif %}{% endfor %}
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
{% endfor %}
|
|
32
|
+
|
|
33
|
+
## Your Task
|
|
34
|
+
|
|
35
|
+
Perform a holistic review of this entire schema and identify **MATERIAL** issues that affect the overall coherence and understanding of the database.
|
|
36
|
+
|
|
37
|
+
Focus on:
|
|
38
|
+
|
|
39
|
+
1. **Schema-Wide Consistency**: Are business concepts described consistently across all tables?
|
|
40
|
+
2. **Relationship Network**: Do the relationships between tables make logical sense?
|
|
41
|
+
3. **Missing Relationships**: Are there implied relationships not captured in foreign keys?
|
|
42
|
+
4. **Business Domain Alignment**: Do all tables fit the stated business domain(s)?
|
|
43
|
+
5. **Naming Convention Issues**: Are there tables that seem misnamed or miscategorized?
|
|
44
|
+
6. **Architectural Patterns**: Do you see patterns (audit, configuration, transaction) that should be documented?
|
|
45
|
+
|
|
46
|
+
## What Counts as MATERIAL
|
|
47
|
+
|
|
48
|
+
**MATERIAL issues** (flag these):
|
|
49
|
+
- Tables described with contradictory purposes
|
|
50
|
+
- Relationship chains that don't make business sense
|
|
51
|
+
- Core business entities misidentified or misdescribed
|
|
52
|
+
- Critical patterns not recognized (e.g., audit trail, versioning)
|
|
53
|
+
- Terminology used inconsistently across tables in ways that confuse understanding
|
|
54
|
+
- Missing schema-level context that would help interpret individual tables
|
|
55
|
+
|
|
56
|
+
**NOT material** (ignore these):
|
|
57
|
+
- Minor wording variations
|
|
58
|
+
- Different description styles
|
|
59
|
+
- Redundant information across tables
|
|
60
|
+
- Grammar or formatting
|
|
61
|
+
- Obvious facts already captured elsewhere
|
|
62
|
+
|
|
63
|
+
## Response Format
|
|
64
|
+
|
|
65
|
+
Generate a JSON response with this exact structure:
|
|
66
|
+
|
|
67
|
+
```json
|
|
68
|
+
{
|
|
69
|
+
"hasMaterialIssues": false,
|
|
70
|
+
"schemaCoherence": "overall | good | fair | poor",
|
|
71
|
+
"overallAssessment": "High-level summary of schema documentation quality",
|
|
72
|
+
"schemaLevelIssues": [
|
|
73
|
+
{
|
|
74
|
+
"issueType": "consistency | relationships | business_domain | naming | architecture | missing_pattern",
|
|
75
|
+
"severity": "high | medium | low",
|
|
76
|
+
"description": "Specific description of the schema-wide issue",
|
|
77
|
+
"affectedTables": ["Table1", "Table2", "Table3"],
|
|
78
|
+
"suggestedSchemaDescription": "If the schema description should be added/updated"
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
"tableIssues": [
|
|
82
|
+
{
|
|
83
|
+
"tableName": "TableName",
|
|
84
|
+
"issueType": "description | business_purpose | relationships | terminology",
|
|
85
|
+
"severity": "high | medium | low",
|
|
86
|
+
"description": "What's wrong with this table's description",
|
|
87
|
+
"suggestedFix": "How to correct the table description"
|
|
88
|
+
}
|
|
89
|
+
],
|
|
90
|
+
"architecturalPatterns": [
|
|
91
|
+
{
|
|
92
|
+
"pattern": "audit_trail | configuration | lookup | transaction | versioning | soft_delete | hierarchy",
|
|
93
|
+
"tables": ["Table1", "Table2"],
|
|
94
|
+
"description": "Pattern identified and how it should be documented"
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
"businessDomainSuggestions": [
|
|
98
|
+
{
|
|
99
|
+
"suggestedDomain": "Domain name",
|
|
100
|
+
"reasoning": "Why this domain applies to this schema",
|
|
101
|
+
"confidence": "high | medium | low"
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
}
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
**Guidelines:**
|
|
108
|
+
- Set `hasMaterialIssues: true` ONLY if corrections are needed
|
|
109
|
+
- Be specific about which tables need description updates
|
|
110
|
+
- Identify architectural patterns that should be explicitly documented
|
|
111
|
+
- Suggest business domains if not already specified
|
|
112
|
+
- Focus on issues that would mislead database users or developers
|
|
113
|
+
|
|
114
|
+
Return ONLY valid JSON. Do not include markdown code fences or explanatory text.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
You are reviewing all table descriptions within the "{{ schemaName }}" schema for consistency and completeness.
|
|
2
|
+
|
|
3
|
+
## Schema Tables
|
|
4
|
+
|
|
5
|
+
{% for table in tables %}
|
|
6
|
+
### {{ table.name }}
|
|
7
|
+
**Description**: {{ table.description }}
|
|
8
|
+
|
|
9
|
+
**Columns**:
|
|
10
|
+
{% for col in table.columns %}
|
|
11
|
+
- {{ col.name }}: {{ col.description }}
|
|
12
|
+
{% endfor %}
|
|
13
|
+
|
|
14
|
+
{% endfor %}
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## Your Task
|
|
19
|
+
|
|
20
|
+
Review the table and column descriptions for consistency, coherence, and completeness.
|
|
21
|
+
|
|
22
|
+
Generate a JSON response with this exact structure:
|
|
23
|
+
|
|
24
|
+
```json
|
|
25
|
+
{
|
|
26
|
+
"schemaDescription": "A high-level description of what this schema contains and its overall purpose",
|
|
27
|
+
"inconsistencies": [
|
|
28
|
+
"Description of any contradictions or inconsistencies found between table descriptions",
|
|
29
|
+
"Note any tables that seem to serve similar purposes but are described differently"
|
|
30
|
+
],
|
|
31
|
+
"suggestions": [
|
|
32
|
+
"Suggestions for improving clarity or completeness",
|
|
33
|
+
"Recommendations for additional context or details"
|
|
34
|
+
]
|
|
35
|
+
}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Guidelines:**
|
|
39
|
+
1. **Schema Description**: Synthesize the table descriptions into a coherent schema-level summary
|
|
40
|
+
2. **Inconsistencies**: Look for:
|
|
41
|
+
- Contradictory descriptions between related tables
|
|
42
|
+
- Similar tables described with different terminology
|
|
43
|
+
- Missing relationships or unclear dependencies
|
|
44
|
+
- Descriptions that don't align with column details
|
|
45
|
+
3. **Suggestions**: Provide actionable recommendations for improvement
|
|
46
|
+
4. **If no issues found**: Return empty arrays for inconsistencies and suggestions
|
|
47
|
+
|
|
48
|
+
**Focus on:**
|
|
49
|
+
- Terminology consistency across tables
|
|
50
|
+
- Logical coherence of the schema as a whole
|
|
51
|
+
- Completeness of explanations
|
|
52
|
+
- Clarity and precision of language
|
|
53
|
+
|
|
54
|
+
Return ONLY valid JSON. Do not include markdown code fences or explanatory text.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
You are comparing two versions of database table documentation to determine if there are MATERIAL differences in informational content.
|
|
2
|
+
|
|
3
|
+
## Table: {{ schemaName }}.{{ tableName }}
|
|
4
|
+
|
|
5
|
+
### Previous Version (Iteration {{ previousIteration }})
|
|
6
|
+
|
|
7
|
+
**Table Description**: {{ previousTableDescription }}
|
|
8
|
+
|
|
9
|
+
**Column Descriptions**:
|
|
10
|
+
{% for col in previousColumns %}
|
|
11
|
+
- **{{ col.columnName }}**: {{ col.description }}
|
|
12
|
+
{% endfor %}
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
### Current Version (Iteration {{ currentIteration }})
|
|
17
|
+
|
|
18
|
+
**Table Description**: {{ currentTableDescription }}
|
|
19
|
+
|
|
20
|
+
**Column Descriptions**:
|
|
21
|
+
{% for col in currentColumns %}
|
|
22
|
+
- **{{ col.columnName }}**: {{ col.description }}
|
|
23
|
+
{% endfor %}
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Your Task
|
|
28
|
+
|
|
29
|
+
Compare these two versions and determine if there are **MATERIAL** changes in informational content. Ignore stylistic differences, rewording, or changes in phrasing that don't affect the actual meaning.
|
|
30
|
+
|
|
31
|
+
Generate a JSON response with this exact structure:
|
|
32
|
+
|
|
33
|
+
```json
|
|
34
|
+
{
|
|
35
|
+
"tableMateriallyChanged": false,
|
|
36
|
+
"tableChangeReasoning": "Explain what material information changed, or why no material change occurred",
|
|
37
|
+
"columnChanges": [
|
|
38
|
+
{
|
|
39
|
+
"columnName": "ColumnName",
|
|
40
|
+
"materiallyChanged": false,
|
|
41
|
+
"changeReasoning": "Brief explanation of what changed or why no material change"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
**Guidelines:**
|
|
48
|
+
|
|
49
|
+
1. **Material Changes** include:
|
|
50
|
+
- Change in actual purpose or meaning of table/column
|
|
51
|
+
- Addition or removal of key information
|
|
52
|
+
- Correction of factual errors
|
|
53
|
+
- Change in data relationships or constraints described
|
|
54
|
+
- Clarification that changes understanding (not just wording)
|
|
55
|
+
|
|
56
|
+
2. **NOT Material Changes** (mark as false):
|
|
57
|
+
- Rewording with same meaning ("flag indicating" vs "boolean flag indicating")
|
|
58
|
+
- Stylistic changes ("stores" vs "contains")
|
|
59
|
+
- Reordering of phrases with same content
|
|
60
|
+
- Grammar improvements that don't change meaning
|
|
61
|
+
- Different phrasing of identical information
|
|
62
|
+
|
|
63
|
+
3. **For each column**:
|
|
64
|
+
- Compare previous vs current description
|
|
65
|
+
- Set `materiallyChanged: true` only if informational content differs
|
|
66
|
+
- Provide reasoning that references specific semantic differences
|
|
67
|
+
|
|
68
|
+
4. **For the table**:
|
|
69
|
+
- Set `tableMateriallyChanged: true` if the table description's meaning changed
|
|
70
|
+
- Consider if the overall understanding of the table's purpose differs
|
|
71
|
+
|
|
72
|
+
**Important:**
|
|
73
|
+
- Be strict about what counts as "material" - we want to avoid unnecessary iterations
|
|
74
|
+
- If you're unsure whether a change is material, it probably isn't
|
|
75
|
+
- Focus on INFORMATION content, not presentation style
|
|
76
|
+
- All columns from the current version must be included in columnChanges array
|
|
77
|
+
|
|
78
|
+
Return ONLY valid JSON. Do not include markdown code fences or explanatory text.
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
# Generate SQL for Single Query
|
|
2
|
+
|
|
3
|
+
You are implementing SQL for a planned reference query. This query will serve as an example for AI agents and developers.
|
|
4
|
+
|
|
5
|
+
## Query Plan
|
|
6
|
+
|
|
7
|
+
**Query ID:** {{ queryPlan.id }}
|
|
8
|
+
**Name:** {{ queryPlan.name }}
|
|
9
|
+
**Description:** {{ queryPlan.description }}
|
|
10
|
+
**Business Purpose:** {{ queryPlan.businessPurpose }}
|
|
11
|
+
**Type:** {{ queryPlan.queryType }}
|
|
12
|
+
**Pattern:** {{ queryPlan.queryPattern }}
|
|
13
|
+
**Complexity:** {{ queryPlan.complexity }}
|
|
14
|
+
|
|
15
|
+
{% if queryPlan.relatedQueryIds.length > 0 %}
|
|
16
|
+
**Related Queries:** {{ queryPlan.relatedQueryIds | join(', ') }}
|
|
17
|
+
⚠️ **ALIGNMENT REQUIRED**: This query must use consistent filtering logic with its related queries!
|
|
18
|
+
{% endif %}
|
|
19
|
+
|
|
20
|
+
## Database Context
|
|
21
|
+
|
|
22
|
+
**Database Type:** {{ databaseType }}
|
|
23
|
+
**Schema:** {{ schemaName }}
|
|
24
|
+
|
|
25
|
+
### Primary Table: {{ focusTable }}
|
|
26
|
+
{{ tableInfo.description }}
|
|
27
|
+
|
|
28
|
+
**Columns:**
|
|
29
|
+
{% for col in tableInfo.columns %}
|
|
30
|
+
- **{{ col.name }}** ({{ col.dataType }}){% if col.isPrimaryKey %} [PK]{% endif %}{% if col.isForeignKey %} [FK → {{ col.foreignKeyReferences.referencesTable }}]{% endif %}
|
|
31
|
+
{% if col.description %}{{ col.description }}{% endif %}
|
|
32
|
+
{% if col.possibleValues %}Values: {{ col.possibleValues | jsoninline }}{% endif %}
|
|
33
|
+
{% endfor %}
|
|
34
|
+
|
|
35
|
+
{% if relatedTables.length > 0 %}
|
|
36
|
+
### Related Tables
|
|
37
|
+
{% for table in relatedTables %}
|
|
38
|
+
**{{ table.name }}** ({{ table.rowCount }} rows)
|
|
39
|
+
{% if table.description %}{{ table.description }}{% endif %}
|
|
40
|
+
|
|
41
|
+
Columns:
|
|
42
|
+
{% for col in table.columns %}
|
|
43
|
+
- {{ col.name }} ({{ col.dataType }}){% if col.isPrimaryKey %} [PK]{% endif %}
|
|
44
|
+
{% endfor %}
|
|
45
|
+
|
|
46
|
+
{% endfor %}
|
|
47
|
+
{% endif %}
|
|
48
|
+
|
|
49
|
+
{% if relatedQueryPlans.length > 0 %}
|
|
50
|
+
## Related Query Plans (for alignment)
|
|
51
|
+
{% for plan in relatedQueryPlans %}
|
|
52
|
+
### {{ plan.name }} (ID: {{ plan.id }})
|
|
53
|
+
- **Type:** {{ plan.queryType }}
|
|
54
|
+
- **Purpose:** {{ plan.businessPurpose }}
|
|
55
|
+
- **Description:** {{ plan.description }}
|
|
56
|
+
{% endfor %}
|
|
57
|
+
|
|
58
|
+
⚠️ **CRITICAL**: Your SQL MUST use filtering logic that aligns with these related queries!
|
|
59
|
+
{% endif %}
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## Task
|
|
64
|
+
|
|
65
|
+
Generate executable, parameterized SQL for this query plan.
|
|
66
|
+
|
|
67
|
+
### Requirements
|
|
68
|
+
|
|
69
|
+
1. **Executable SQL**: Must be valid SQL for {{ databaseType }}
|
|
70
|
+
2. **Parameterized**: Use `@ParameterName` for dynamic values
|
|
71
|
+
3. **Efficient**: Use appropriate indexes (primary keys, foreign keys)
|
|
72
|
+
4. **Well-Formatted**: Readable, properly indented SQL
|
|
73
|
+
5. **Documented Logic**: Explain filtering, aggregation, and join rules
|
|
74
|
+
|
|
75
|
+
### Parameter Guidelines
|
|
76
|
+
- Use descriptive parameter names: `@StartDate`, `@MemberID`, `@Status`
|
|
77
|
+
- Include diverse example values that reflect real data patterns
|
|
78
|
+
- Mark required vs. optional parameters
|
|
79
|
+
- Provide default values where appropriate
|
|
80
|
+
|
|
81
|
+
### Business Logic Documentation
|
|
82
|
+
Document the **rules and logic** that make this query work correctly:
|
|
83
|
+
|
|
84
|
+
**Filtering Rules**: What filters are applied and why
|
|
85
|
+
- Example: "Always filter by Status='Active' to exclude archived records"
|
|
86
|
+
- Example: "Date range filters use >= StartDate AND < EndDate for consistency"
|
|
87
|
+
|
|
88
|
+
**Aggregation Rules**: How data is grouped and calculated
|
|
89
|
+
- Example: "Use COUNT(DISTINCT MemberID) to avoid double-counting"
|
|
90
|
+
- Example: "GROUP BY uses fiscal quarters (Oct-Dec = Q1)"
|
|
91
|
+
|
|
92
|
+
**Join Rules**: How tables are related
|
|
93
|
+
- Example: "LEFT JOIN ensures all events included even without registrations"
|
|
94
|
+
- Example: "INNER JOIN filters to only members with active certifications"
|
|
95
|
+
|
|
96
|
+
**Alignment Notes** (if relatedQueryIds exist):
|
|
97
|
+
- Explicitly state how filtering must match related queries
|
|
98
|
+
- Example: "MUST filter by Status='Completed' to match summary query totals"
|
|
99
|
+
|
|
100
|
+
### Sample Result Columns
|
|
101
|
+
Define what columns the query returns and what they mean:
|
|
102
|
+
- Column name
|
|
103
|
+
- Data type
|
|
104
|
+
- Description
|
|
105
|
+
- Whether it's a measure (numeric metric) or dimension (grouping)
|
|
106
|
+
|
|
107
|
+
---
|
|
108
|
+
|
|
109
|
+
## Output Format
|
|
110
|
+
|
|
111
|
+
Return a JSON object with this structure:
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"sqlQuery": "SELECT ...",
|
|
116
|
+
"parameters": [
|
|
117
|
+
{
|
|
118
|
+
"name": "ParameterName",
|
|
119
|
+
"dataType": "VARCHAR|INT|DATE|...",
|
|
120
|
+
"description": "What this parameter controls",
|
|
121
|
+
"required": true,
|
|
122
|
+
"defaultValue": "DefaultIfAny",
|
|
123
|
+
"exampleValues": ["Example1", "Example2", "Example3"]
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"sampleResultColumns": [
|
|
127
|
+
{
|
|
128
|
+
"name": "ColumnName",
|
|
129
|
+
"dataType": "VARCHAR|INT|DECIMAL|...",
|
|
130
|
+
"description": "What this column contains",
|
|
131
|
+
"isMeasure": false,
|
|
132
|
+
"isDimension": true
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
"filteringRules": [
|
|
136
|
+
"Explicit rule about how filtering works in this query"
|
|
137
|
+
],
|
|
138
|
+
"aggregationRules": [
|
|
139
|
+
"Explicit rule about how aggregation works (if applicable)"
|
|
140
|
+
],
|
|
141
|
+
"joinRules": [
|
|
142
|
+
"Explicit rule about how tables are joined (if applicable)"
|
|
143
|
+
],
|
|
144
|
+
"alignmentNotes": "How this query's filtering logic aligns with related queries (if relatedQueryIds exist)"
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
**IMPORTANT:**
|
|
149
|
+
- SQL must be executable against {{ databaseType }}
|
|
150
|
+
- All JSON must be valid and parseable
|
|
151
|
+
- Use actual column names from the schema above
|
|
152
|
+
- Parameters use `@ParameterName` syntax for {{ databaseType }}
|
|
153
|
+
{% if queryPlan.relatedQueryIds.length > 0 %}
|
|
154
|
+
- **CRITICAL**: Filtering logic MUST align with related queries to prevent mismatched totals!
|
|
155
|
+
{% endif %}
|