Skip to content

Commit 6de7595

Browse files
authored
chore(ph-ai): adjusted sql prompt guardralsi (#42276)
1 parent da6bdd0 commit 6de7595

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

ee/hogai/chat_agent/sql/prompts.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
You are an expert in writing HogQL. HogQL is PostHog's variant of SQL that supports most of ClickHouse SQL. We're going to use terms "HogQL" and "SQL" interchangeably.
33
You write HogQL based on a prompt. You don't help with other knowledge. You are provided with the current HogQL query that the user is editing. You have access to the core memory about the user's company and product in the <core_memory> tag. Use this memory in your responses.
44
5+
CRITICAL - Function name casing:
6+
- HogQL function names are CASE-SENSITIVE and use camelCase (not snake_case or lowercase).
7+
- Common mistakes to avoid:
8+
- WRONG: format_datetime, formatdatetime → CORRECT: formatDateTime
9+
- WRONG: to_timezone, totimezone → CORRECT: toTimeZone
10+
- WRONG: todatetime, to_datetime → CORRECT: toDateTime
11+
- WRONG: to_date, todate → CORRECT: toDate
12+
- WRONG: countif → CORRECT: countIf
13+
- Timezone strings are also case-sensitive: use 'UTC' not 'utc', 'America/New_York' not 'america/new_york'.
14+
515
Important HogQL differences versus other SQL dialects:
616
- JSON properties are accessed using `properties.foo.bar` instead of `properties->foo->bar` for property keys without special characters.
717
- JSON properties can also be accessed using `properties.foo['bar']` if there's any special character (note the single quotes).
@@ -181,7 +191,7 @@
181191
## Functions and aggregations
182192
183193
You can filter, modify, or aggregate accessed data with [supported ClickHouse functions](/docs/sql/clickhouse-functions.md) like `dateDiff()` and `concat()` and [aggregations](/docs/hogql/aggregations.md) like `sumIf()` and `count()`.
184-
Functions are always written in camel case for example `countIf()` instead of `COUNTIF()` or `COUNTIf`.
194+
REMINDER: Functions use camelCase (e.g., `countIf`, `formatDateTime`, `toTimeZone`) - see the CRITICAL section above.
185195
186196
Here are some of the most common and useful ones:
187197

ee/hogai/eval/ci/max_tools/eval_hogql_generator_tool.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,13 @@ async def eval_tool_generate_hogql_query(call_generate_hogql_query, database_sch
234234
expected="SELECT p.id AS person_id, p.properties.email AS email, p.properties.org AS organization FROM persons p WHERE p.properties.email NOT LIKE '%@test.com' AND (coalesce(variables.org, '') = '' OR p.properties.org = variables.org) ORDER BY p.created_at DESC LIMIT 1000",
235235
metadata=metadata,
236236
),
237+
EvalCase(
238+
input=EvalInput(
239+
instructions="Show me daily event counts for 'buy_button_clicked' events from Nov 25-26 2025, formatted as YYYY-MM-DD in UTC timezone",
240+
),
241+
expected="SELECT formatDateTime(toTimeZone(timestamp, 'UTC'), '%Y-%m-%d') AS day, count() FROM events WHERE event = 'buy_button_clicked' AND timestamp >= toDateTime('2025-11-25 00:00:00') AND timestamp <= toDateTime('2025-11-26 23:59:59') GROUP BY day ORDER BY day DESC",
242+
metadata=metadata,
243+
),
237244
],
238245
pytestconfig=pytestconfig,
239246
)

0 commit comments

Comments
 (0)