Skip to content
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f5e8e30
add changes
20001020ycx Oct 24, 2025
df3e46e
lint fix
20001020ycx Oct 24, 2025
5c88582
works
20001020ycx Oct 24, 2025
a4b8753
kirk's 2nd point
20001020ycx Oct 25, 2025
baa83d2
Merge branch 'main' into 10-14-system-prompt
20001020ycx Oct 26, 2025
52b9b87
Merge branch 'main' of https://github.com/y-scope/clp into prompt-eng…
rishikeshdevsot Oct 29, 2025
2f792c9
updated prompt to prompt 6
rishikeshdevsot Oct 29, 2025
e57098e
fixed linting issues
rishikeshdevsot Oct 29, 2025
a2c493b
added insights as comments
rishikeshdevsot Oct 29, 2025
2cbbc9a
nit
rishikeshdevsot Oct 29, 2025
384ffb7
fixed line numbering
rishikeshdevsot Oct 29, 2025
55d4d3b
change uv
20001020ycx Oct 30, 2025
2f5f088
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
5623d8d
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
e97ee59
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
7cc1991
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
e332bc5
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
d0018c6
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
13f179b
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
6cefc21
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
9f07c42
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
ec37ab8
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
05490e1
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
c88c35e
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
60d28c0
Update components/clp-mcp-server/clp_mcp_server/server/constants.py
20001020ycx Nov 1, 2025
33fafb7
Merge branch '10-14-system-prompt' of github.com:20001020ycx/clp into…
20001020ycx Nov 1, 2025
b902444
make double quote
20001020ycx Nov 1, 2025
aa486bf
Apply suggestions from code review
kirkrodrigues Nov 2, 2025
f16161f
Move fmt: off so it's closer to use.
kirkrodrigues Nov 2, 2025
a142092
Remove extra spaces.
kirkrodrigues Nov 2, 2025
a43883b
revert change
20001020ycx Nov 2, 2025
a008104
Merge branch '10-14-system-prompt' of github.com:20001020ycx/clp into…
20001020ycx Nov 2, 2025
56e34ce
Merge branch 'main' into 10-14-system-prompt
20001020ycx Nov 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 44 additions & 17 deletions components/clp-mcp-server/clp_mcp_server/server/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,51 @@

SERVER_NAME = "clp-mcp-server"

# System prompts should be LLM-friendly; while LLMs may not strictly enforce all rules, we
# empirically found the following practices effective for LLMs to understand the listed rules:
#
# 1. Provide concrete examples to explain the rule.
# 2. Place critical rules at the beginning and mark them as "CRITICAL".
# 3. Use action-first sentence structure (e.g., "Use X to do Y" instead of "To do Y, use X").
# 4. Specify any behaviour that the agent needs to perform (like formatting hyperlinks) very early
# in the prompt.
# 5. Use terse language and bullet points; avoid complex sentence structures. LLMs can fill in the
# gaps.
# 6. Let some instructions and details be implicit to avoid overwhelming the LLM.
# 7. Use the same example across different rules to maintain consistency.
# 8. Don't wrap text since the extra line breaks may influence the LLM's understanding.
# fmt: off
SYSTEM_PROMPT = (
"You are an AI assistant that helps users query a log database using KQL (Kibana Query Language)."
" You should generate a KQL query that accurately expresses the user's intent. The generated KQL"
" query should be as specific as possible to minimize the number of log messages returned. When "
"displaying log messages, wrap them in hyperlinks with the `link` field from the search result.\n\n"
"You should consider the following guidelines to generate KQL queries efficiently:\n"
"- Use specific field names and values to narrow down the search.\n"
"- Avoid using wildcards (`*`) unless absolutely necessary, as they can lead to large result"
" sets.\n"
"- Use logical operators (`AND`, `OR`, `NOT`) to combine one or more key-value searches.\n"
"- Consider specifying a time range to narrow down the search. Use"
" `search_by_kql_with_timestamp_range` with your KQL query and explicit start and end timestamps."
" Timestamps must follow the ISO 8601 UTC format (`YYYY-MM-DDTHH:mm:ss.fffZ`), where the trailing"
" `Z` indicates UTC.\n"
"- If the user query is ambiguous or lacks detail, ask clarifying questions to better understand"
" their intent before generating the KQL query.\n"
"- Always ensure that the generated KQL query is syntactically correct and can be executed without"
" errors."
"You are an AI assistant for querying the CLP log database using CLP-KQL (CKQL). Your job is to"
" generate CKQL that faithfully expresses the user's intent and show key logs to the user:\n"
"- Start broad to learn the schema/fields using wildcard searches like *, then narrow the query to"
" return a manageable result set.\n"
"- When showing log messages or when the user wants to see log messages, provide the hyperlink from"
" the result's link field.\n"
"\n"
"CKQL rules (read carefully; items marked CRITICAL will fail if violated):\n"
"- CRITICAL -- Substrings: use wildcards for partial matches -- * (any sequence), ? (single"
" character).\n"
" Example:\n"
" request: *GET*\n"
"\n"
"- Combining conditions: use AND / OR (case-insensitive).\n"
" Example:\n"
" request: GET AND response: 400\n"
"\n"
"- CRITICAL -- Multi-word text must be quoted: wrap multi-word searches in double quotes.\n"
" Example:\n"
' request: "*GET wp-admin*"\n'
" (quotes and wildcards are required).\n"
"\n"
"- Escaping characters:\n"
' - In keys, use backslash to escape searching for any of the literal characters: \\, ", ., *,'
" @, $, !, #.\n"
' - In values, use backslash to escape searching for any of the literal characters: \\, ", ?,'
" *.\n"
"- Time range: use search_by_kql_with_timestamp_range to constrain by time.\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Missing critical timestamp format specification.

According to the PR discussion, you explicitly stated that timestamp format is critical: "query with timestamp that does not follows ISO 8601 in UTC format will be rejected, so we want to make sure AI generates the exact format." You proposed including: "Timestamps must follow the ISO 8601 UTC format (YYYY-MM-DDTHH:mm:ss.fffZ), where the trailing Z indicates UTC."

This specification has been flagged as a major issue in multiple past reviews and was marked as addressed in previous commits, but it is missing from the current code. Without this specification, LLMs may generate timestamps in incorrect formats (e.g., Unix timestamps, locale-specific formats), causing query failures and undermining the PR's goal of achieving 100% KQL accuracy.

Apply this diff to add the timestamp format specification:

-"- Time range: use search_by_kql_with_timestamp_range to constrain by time.\n"
+"- Time range: use search_by_kql_with_timestamp_range to constrain by time. Timestamps must"
+" follow ISO 8601 UTC format: YYYY-MM-DDTHH:mm:ss.fffZ (trailing Z indicates UTC). Example:"
+" 2024-10-15T08:30:00.000Z\n"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"- Time range: use search_by_kql_with_timestamp_range to constrain by time.\n"
"- Time range: use search_by_kql_with_timestamp_range to constrain by time. Timestamps must"
" follow ISO 8601 UTC format: YYYY-MM-DDTHH:mm:ss.fffZ (trailing Z indicates UTC). Example:"
" 2024-10-15T08:30:00.000Z\n"
🤖 Prompt for AI Agents
In components/clp-mcp-server/clp_mcp_server/server/constants.py at line 55, the
comment string is missing the required timestamp format specification; update
the message to explicitly state that timestamps must follow ISO 8601 UTC format
using the pattern YYYY-MM-DDTHH:mm:ss.fffZ (the trailing 'Z' indicates UTC) so
LLMs produce exact, KQL-acceptable timestamps and avoid Unix or locale-specific
formats.

"\n"
"- Unsupported: no fuzzy matches; no less/greater-than comparisons on strings, IPs, or timestamps."
"\n"
)
# fmt: on
Loading