Skip to content

Commit cc9b760

Browse files
authored
Add centralized prompt template system (#3971)
Creates reusable prompt template system with Go text/template. ## Changes - Add ExecuteTemplate() and MustExecuteTemplate() helpers - Embed templates using //go:embed - Add auth error, U2M, and initialization message templates - Enhance aitools auth error with profile selection guidance ## Dependencies None - standalone system ## Testing - Compiles successfully - Templates properly embedded
1 parent 61c1238 commit cc9b760

File tree

5 files changed

+119
-0
lines changed

5 files changed

+119
-0
lines changed

experimental/aitools/tools/prompts/auth_error.tmpl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@ To authenticate, please run:
1010

1111
Replace <your-workspace-url> with your Databricks workspace URL (e.g., mycompany.cloud.databricks.com).
1212

13+
Alternatives:
14+
15+
1. Run `databricks auth profiles` to list available profiles and set the `DATABRICKS_CONFIG_PROFILE` to the profile you want to use.
16+
2. Set the `DATABRICKS_CONFIG_HOST` to the host of the workspace you want to use.
17+
18+
You might have to leave the coding agent to set these environment variables and then come back to it.
19+
1320
Don't have a Databricks account? You can set up a fully free account for experimentation at:
1421
https://docs.databricks.com/getting-started/free-edition
1522

23+
Do not run anything else before authenticating successfully.
24+
1625
Once authenticated, you can use this tool again
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{- /*
2+
* Actionable rror message shown when user is not authenticated to Databricks.
3+
*
4+
*/ -}}
5+
6+
Not authenticated to Databricks
7+
8+
I need to know either the Databricks workspace URL or the Databricks profile name.
9+
You can list the available profiles by running `databricks auth profiles`.
10+
11+
ASK the user which of the configured profiles or databricks workspace URL they want to use.
12+
Only then call the `databricks_configure_auth` tool to configure the authentication.
13+
14+
Do not run anything else before authenticating successfully.
15+
Once authenticated, you can use this tool again
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{- /*
2+
* Message shown when user knows the workspace URL but is not authenticated to Databricks.
3+
*
4+
*/ -}}
5+
6+
You are not authenticated to Databricks.
7+
8+
To authenticate, please run:
9+
databricks auth login --profile <profile_name> --host {{.WorkspaceURL}}
10+
11+
Ask for a profile name or use `DEFAULT`.
12+
13+
Don't have a Databricks account? You can set up a fully free account for experimentation at:
14+
https://docs.databricks.com/getting-started/free-edition
15+
16+
Do not run anything else before authenticating successfully.
17+
Once authenticated, you can use this tool again
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Your session in Databricks MCP has been successfully initialized. Here are the guidelines to follow while working on projects using databricks_mcp tools:
2+
3+
## Project State Management:
4+
This project uses a state file (`.edda_state`) managed by edda MCP to enforce the correct workflow order:
5+
1. **Scaffolded**: `scaffold_data_app` creates project structure from template (starts in this state)
6+
2. **Validated**: `validate_data_app` runs build + tests in sandbox, computes BLAKE3 checksum of package.json and all core source files
7+
3. **Deployed**: `deploy_databricks_app` deploys to Databricks Apps, but ONLY if checksum hasn't changed since validation
8+
9+
Re-validation is allowed (Deployed → Validated) to update the checksum after intentional changes. The databricks_mcp tools enforce these state transitions and prevent invalid state changes.
10+
11+
## Workflow:
12+
- Projects MUST end with validate_project to verify build + tests pass
13+
- Bias towards backend code when the task allows implementation in multiple places
14+
- Always add tests for what you're implementing, put them next to the code (e.g. src/*.test.ts)
15+
- When working with Databricks or other services, use real API calls in tests (no mocks) to verify end-to-end functionality, unless explicitly instructed otherwise. It can be done on subset of data if applicable.
16+
- Do NOT create summary files, reports, or README unless explicitly requested
17+
- When not sure about the user's intent, ask clarifying questions before proceeding. For example, if user asks for "a data app to analyze sales data", ask for more details on data sources and analysis goals. Do not make assumptions regarding their needs and data sources.
18+
- However, stick to the technical stack initialized by the `scaffold_data_app` as it has been approved by the management and battle-tested in production.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package prompts
2+
3+
import (
4+
"bytes"
5+
"embed"
6+
"fmt"
7+
"text/template"
8+
)
9+
10+
//go:embed *.tmpl
11+
var promptTemplates embed.FS
12+
13+
// ExecuteTemplate loads and executes a template with the given name and data.
14+
func ExecuteTemplate(name string, data any) (string, error) {
15+
tmplContent, err := promptTemplates.ReadFile(name)
16+
if err != nil {
17+
return "", fmt.Errorf("failed to read template %s: %w", name, err)
18+
}
19+
20+
tmpl, err := template.New(name).Parse(string(tmplContent))
21+
if err != nil {
22+
return "", fmt.Errorf("failed to parse template %s: %w", name, err)
23+
}
24+
25+
var buf bytes.Buffer
26+
if err := tmpl.Execute(&buf, data); err != nil {
27+
return "", fmt.Errorf("failed to execute template %s: %w", name, err)
28+
}
29+
30+
return buf.String(), nil
31+
}
32+
33+
// MustExecuteTemplate is like ExecuteTemplate but panics on error.
34+
// Use this only when template execution errors are programming errors.
35+
func MustExecuteTemplate(name string, data any) string {
36+
result, err := ExecuteTemplate(name, data)
37+
if err != nil {
38+
panic(err)
39+
}
40+
return result
41+
}
42+
43+
// LoadTemplate loads a template without executing it.
44+
// Returns the raw template content as a string.
45+
func LoadTemplate(name string) (string, error) {
46+
tmplContent, err := promptTemplates.ReadFile(name)
47+
if err != nil {
48+
return "", fmt.Errorf("failed to read template %s: %w", name, err)
49+
}
50+
return string(tmplContent), nil
51+
}
52+
53+
// MustLoadTemplate is like LoadTemplate but panics on error.
54+
func MustLoadTemplate(name string) string {
55+
result, err := LoadTemplate(name)
56+
if err != nil {
57+
panic(err)
58+
}
59+
return result
60+
}

0 commit comments

Comments
 (0)