codeant-ai-for-open-source[bot] commented on code in PR #40448:
URL: https://github.com/apache/superset/pull/40448#discussion_r3305628319


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -444,6 +445,25 @@ def sanitize_chart_info_for_llm_context(chart_info: 
ChartInfo) -> ChartInfo:
                 | frozenset({"cache_key", "database", "database_name", 
"schema"})
             ),
         )
+        # ``metrics`` is in the bulk exclusion list (SIMPLE-metric content is
+        # bounded). SQL-metric adhoc dicts carry LLM-controlled strings that
+        # still need ``<UNTRUSTED-CONTENT>`` wrapping.
+        form_data = payload.get("form_data")
+        metrics = form_data.get("metrics") if isinstance(form_data, dict) else 
None
+        if isinstance(metrics, list):
+            for index, metric in enumerate(metrics):
+                if isinstance(metric, dict) and metric.get("expressionType") 
== "SQL":
+                    for key in ("sqlExpression", "label"):
+                        if isinstance(metric.get(key), str):
+                            metric[key] = sanitize_for_llm_context(
+                                metric[key],
+                                field_path=(
+                                    "form_data",
+                                    "metrics",
+                                    str(index),
+                                    key,
+                                ),
+                            )
 

Review Comment:
   **🟠 Architect Review — HIGH**
   
   SQL adhoc metrics in ChartInfo form_data under the singular "metric" key 
(used by pie and big-number charts) are excluded from sanitize_for_llm_context 
and are not covered by the new SQL-metric wrapper, so their sqlExpression/label 
strings are returned to the LLM without <UNTRUSTED-CONTENT> wrapping.
   
   **Suggestion:** Extend the SQL-metric wrapping in 
sanitize_chart_info_for_llm_context to also cover form_data["metric"] (and any 
other singular metric containers) in addition to the existing 
form_data["metrics"] handling, so that sqlExpression and label are consistently 
wrapped before being exposed to the LLM.
   
   
   [Fix in 
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=847c088050b549a29a1f4eeb21b60616&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 | [Fix in VSCode 
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=847c088050b549a29a1f4eeb21b60616&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is an **Architect / Logical Review** comment left during a code review. 
These reviews are first-class, important findings — not optional suggestions. 
Do NOT dismiss this as a 'big architectural change' just because the title says 
architect review; most of these can be resolved with a small, localized fix 
once the intent is understood.
   
   **Path:** superset/mcp_service/chart/schemas.py
   **Line:** 448:467
   **Comment:**
        *HIGH: SQL adhoc metrics in ChartInfo form_data under the singular 
"metric" key (used by pie and big-number charts) are excluded from 
sanitize_for_llm_context and are not covered by the new SQL-metric wrapper, so 
their sqlExpression/label strings are returned to the LLM without 
<UNTRUSTED-CONTENT> wrapping.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   If a suggested approach is provided above, use it as the authoritative 
instruction. If no explicit code suggestion is given, you MUST still draft and 
apply your own minimal, localized fix — do not punt back with 'no suggestion 
provided, review manually'. Keep the change as small as possible: add a guard 
clause, gate on a loading state, reorder an await, wrap in a conditional, etc. 
Do not refactor surrounding code or expand scope beyond the finding.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to