You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "richardfogaca (via GitHub)" <gi...@apache.org> on 2026/04/29 00:49:57 UTC

[PR] fix(mcp): sanitize read path output for LLM context [superset]

richardfogaca opened a new pull request, #39738:
URL: https://github.com/apache/superset/pull/39738

   ### SUMMARY
   
   Sanitizes MCP read-path output before it is exposed to LLM context by wrapping user-controlled descriptive fields in explicit untrusted-content delimiters.
   
   This covers dashboard, dataset, chart info, chart data, chart SQL, chart preview, and SQL Lab context responses while preserving response shape for callers. The sanitizer is centralized in the MCP service utilities and applied at tool/schema boundaries where read-path payloads are assembled.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   Not applicable. This is MCP service response hardening with unit coverage.
   
   ### TESTING INSTRUCTIONS
   
   Run:
   
   ```bash
   PYENV_VERSION=superset pytest tests/unit_tests/mcp_service/utils/test_sanitization.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_info.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_sql.py tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py -q
   ```
   
   Also run:
   
   ```bash
   PYENV_VERSION=superset pre-commit run --files superset/mcp_service/chart/schemas.py superset/mcp_service/chart/tool/get_chart_data.py superset/mcp_service/chart/tool/get_chart_info.py superset/mcp_service/chart/tool/get_chart_preview.py superset/mcp_service/chart/tool/get_chart_sql.py superset/mcp_service/dashboard/schemas.py superset/mcp_service/dashboard/tool/get_dashboard_info.py superset/mcp_service/dataset/schemas.py superset/mcp_service/sql_lab/tool/open_sql_lab_with_context.py superset/mcp_service/utils/__init__.py superset/mcp_service/utils/sanitization.py tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_info.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_sql.py tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py tests/unit_tests/mcp_service/dashboard/too
 l/test_dashboard_tools.py tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py tests/unit_tests/mcp_service/utils/test_sanitization.py
   ```
   
   Validated locally:
   
   - `303 passed in 8.81s`
   - Pre-commit passed for all changed files.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "richardfogaca (via GitHub)" <gi...@apache.org>.
richardfogaca merged PR #39738:
URL: https://github.com/apache/superset/pull/39738


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "richardfogaca (via GitHub)" <gi...@apache.org>.
richardfogaca commented on PR #39738:
URL: https://github.com/apache/superset/pull/39738#issuecomment-4346019107

   @aminghadersohi Richard's agent here. I pushed `3c6473d231115ecb08109feb57cb693c1854308a` to address the remaining review notes:
   
   - Fixed the already-wrapped string path so only the outer trust-boundary delimiters remain raw; embedded delimiters inside the wrapped content are escaped, with a regression test for the crafted bypass case.
   - Added `datasource_name` to the `ChartSql` LLM-context sanitizer and updated the helper tests to assert the wrapped value.
   - Sanitized chart/dashboard tag `name` and `description` fields in the read responses, with serializer coverage for both.
   
   The earlier follow-up commit already covered `certified_by` for chart/dashboard and dashboard `css`. I also kept the two Copilot items as false positives: excluded operational fields are delimiter-escaped, and the Vega-Lite data guard is already present.
   
   Validation run locally:
   
   - `PYENV_VERSION=superset pytest tests/unit_tests/mcp_service/utils/test_sanitization.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_info.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py tests/unit_tests/mcp_service/chart/tool/test_get_chart_sql.py tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py -q`
   - `PYENV_VERSION=superset pre-commit run --files ...`
   


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #39738:
URL: https://github.com/apache/superset/pull/39738#issuecomment-4340135940

   ### <span aria-hidden="true">βœ…</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">πŸ”¨</span> Latest commit | 6600a22eccbf6cb6b55425b66c850818f6fe8c01 |
   |<span aria-hidden="true">πŸ”</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/69f155b51cbff300088a75d6 |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-39738--superset-docs-preview.netlify.app](https://deploy-preview-39738--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">πŸ“±</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTM5NzM4LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.imNLZBw7Z2ivrW2kaY7U_O7t-a97A99_L_TqfnYvzQc)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-39738--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #39738:
URL: https://github.com/apache/superset/pull/39738#issuecomment-4340210520

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/39738?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `19.87952%` with `133 lines` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 55.43%. Comparing base ([`4b42f82`](https://app.codecov.io/gh/apache/superset/commit/4b42f82f13687befe7e56bf904f78336630ff979?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`4914f88`](https://app.codecov.io/gh/apache/superset/commit/4914f8837d8b98e8d14461a9ff0f1fb63828507b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/39738?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [...perset/mcp\_service/chart/tool/get\_chart\_preview.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fget_chart_preview.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC9nZXRfY2hhcnRfcHJldmlldy5weQ==) | 9.37% | [29 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...t/mcp\_service/dashboard/tool/get\_dashboard\_info.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fdashboard%2Ftool%2Fget_dashboard_info.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvZGFzaGJvYXJkL3Rvb2wvZ2V0X2Rhc2hib2FyZF9pbmZvLnB5) | 20.83% | [19 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/utils/sanitization.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Futils%2Fsanitization.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvdXRpbHMvc2FuaXRpemF0aW9uLnB5) | 28.00% | [18 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [...\_service/sql\_lab/tool/open\_sql\_lab\_with\_context.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fsql_lab%2Ftool%2Fopen_sql_lab_with_context.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2Uvc3FsX2xhYi90b29sL29wZW5fc3FsX2xhYl93aXRoX2NvbnRleHQucHk=) | 23.52% | [13 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/chart/tool/get\_chart\_data.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fget_chart_data.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC9nZXRfY2hhcnRfZGF0YS5weQ==) | 14.28% | [12 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/dashboard/schemas.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fdashboard%2Fschemas.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvZGFzaGJvYXJkL3NjaGVtYXMucHk=) | 16.66% | [10 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/chart/schemas.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Fschemas.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvc2NoZW1hcy5weQ==) | 25.00% | [9 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/chart/tool/get\_chart\_info.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fget_chart_info.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC9nZXRfY2hhcnRfaW5mby5weQ==) | 18.18% | [9 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/dataset/schemas.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fdataset%2Fschemas.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvZGF0YXNldC9zY2hlbWFzLnB5) | 18.18% | [9 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [superset/mcp\_service/chart/tool/get\_chart\_sql.py](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fchart%2Ftool%2Fget_chart_sql.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvY2hhcnQvdG9vbC9nZXRfY2hhcnRfc3FsLnB5) | 28.57% | [5 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/39738?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (4b42f82) and HEAD (4914f88). Click for more details.
   > 
   > <details><summary>HEAD has 43 uploads less than BASE</summary>
   >
   >| Flag | BASE (4b42f82) | HEAD (4914f88) |
   >|------|------|------|
   >|python|39|2|
   >|presto|4|1|
   >|hive|4|1|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #39738      +/-   ##
   ==========================================
   - Coverage   64.49%   55.43%   -9.06%     
   ==========================================
     Files        2566     2566              
     Lines      133960   134107     +147     
     Branches    31116    31147      +31     
   ==========================================
   - Hits        86394    74346   -12048     
   - Misses      46071    59107   +13036     
   + Partials     1495      654     -841     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Ξ” | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.70% <19.87%> (-0.05%)` | :arrow_down: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `41.46% <19.87%> (-0.05%)` | :arrow_down: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `41.54% <19.87%> (-20.30%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/39738/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/superset/pull/39738?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #39738:
URL: https://github.com/apache/superset/pull/39738#discussion_r3161162606


##########
superset/mcp_service/chart/schemas.py:
##########
@@ -186,6 +187,11 @@ class ChartError(BaseModel):
     )
     model_config = ConfigDict(ser_json_timedelta="iso8601")
 
+    @field_validator("error")
+    @classmethod
+    def sanitize_error_for_llm_context(cls, value: str) -> str:
+        return sanitize_for_llm_context(value, field_path=("error",))

Review Comment:
   **Suggestion:** Add a docstring to this newly added method so it complies with the requirement that new function definitions are documented. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   This is a newly added function definition and it has no docstring. The custom rule cited by the suggestion requires new function definitions to be documented, so the violation is real in the current file.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmcp_service%2Fchart%2Fschemas.py%0A%2A%2ALine%3A%2A%2A%20190%3A193%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20docstring%20to%20this%20newly%20added%20method%20so%20it%20complies%20with%20the%20requirement%20that%20new%20function%20definitions%20are%20documented.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix 
 in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmcp_service%2Fchart%2Fschemas.py%0A%2A%2ALine%3A%2A%2A%20190%3A193%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20docstring%20to%20this%20newly%20added%20method%20so%20it%20complies%20with%20the%20requirement%20that%20new%20function%20definitions%20are%20documented.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/chart/schemas.py
   **Line:** 190:193
   **Comment:**
   	*Custom Rule: Add a docstring to this newly added method so it complies with the requirement that new function definitions are documented.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=d6d7d990755bff1767fba13cb6c04774950c11948432ab144b1f9093be91b98f&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=d6d7d990755bff1767fba13cb6c04774950c11948432ab144b1f9093be91b98f&reaction=dislike'>πŸ‘Ž</a>



##########
superset/mcp_service/dataset/schemas.py:
##########
@@ -283,6 +284,11 @@ class DatasetError(BaseModel):
     timestamp: str | datetime | None = Field(None, description="Error timestamp")
     model_config = ConfigDict(ser_json_timedelta="iso8601")
 
+    @field_validator("error")
+    @classmethod
+    def sanitize_error_for_llm_context(cls, value: str) -> str:
+        return sanitize_for_llm_context(value, field_path=("error",))

Review Comment:
   **Suggestion:** Add a docstring to this newly introduced validator method so all new method definitions are documented. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The newly added validator method has no docstring, so it does not satisfy the stated rule that new method definitions must be documented.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmcp_service%2Fdataset%2Fschemas.py%0A%2A%2ALine%3A%2A%2A%20287%3A290%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20docstring%20to%20this%20newly%20introduced%20validator%20method%20so%20all%20new%20method%20definitions%20are%20documented.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://a
 pp.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset%2Fmcp_service%2Fdataset%2Fschemas.py%0A%2A%2ALine%3A%2A%2A%20287%3A290%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20docstring%20to%20this%20newly%20introduced%20validator%20method%20so%20all%20new%20method%20definitions%20are%20documented.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/dataset/schemas.py
   **Line:** 287:290
   **Comment:**
   	*Custom Rule: Add a docstring to this newly introduced validator method so all new method definitions are documented.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=c5986118662e8361804cdefcbe99395a4af9c2708c734ed8dbb1a5481cb2db80&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=c5986118662e8361804cdefcbe99395a4af9c2708c734ed8dbb1a5481cb2db80&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py:
##########
@@ -409,7 +412,86 @@ def test_serialize_chart_object_with_certification_fields(self):
 
         assert result is not None
         assert result.certified_by == "Data Team"
-        assert result.certification_details == "Verified Q1 2026 metrics"
+        assert result.certification_details == sanitize_for_llm_context(
+            "Verified Q1 2026 metrics"
+        )
+
+    def test_serialize_chart_object_sanitizes_chart_metadata_and_filters(self):

Review Comment:
   **Suggestion:** Add an explicit return type annotation to this newly added test method (for example, `-> None`) to satisfy the typing requirement for new function definitions. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The new test method is defined without an explicit return annotation. The repository's Python typing configuration enforces untyped definitions, so adding `-> None` is a real typing-related fix.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_generate_chart.py%0A%2A%2ALine%3A%2A%2A%20419%3A419%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20this%20newly%20added%20test%20method%20%28for%20example%2C%20%60-%3E%20None%60%29%20to%20satisfy%20the%20typing%20requirement%20for%20new%20function%20definitions.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20com
 ments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_generate_chart.py%0A%2A%2ALine%3A%2A%2A%20419%3A419%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20this%20newly%20added%20test%20method%20%28for%20example%2C%20%60-%3E%20None%60%29%20to%20satisfy%20the%20typing%20requirement%20for%20new%20function%20definitions.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20
 rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py
   **Line:** 419:419
   **Comment:**
   	*Custom Rule: Add an explicit return type annotation to this newly added test method (for example, `-> None`) to satisfy the typing requirement for new function definitions.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=c1270d165cd9d400e165750ffb261cea3176a413fc6cb63b58f31e464b45f4b2&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=c1270d165cd9d400e165750ffb261cea3176a413fc6cb63b58f31e464b45f4b2&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/chart/tool/test_get_chart_info.py:
##########
@@ -40,6 +45,10 @@
 )
 
 
+def _wrapped(value: str) -> str:
+    return f"{LLM_CONTEXT_OPEN_DELIMITER}\n{value}\n{LLM_CONTEXT_CLOSE_DELIMITER}"

Review Comment:
   **Suggestion:** Add a short docstring to this newly introduced helper function to satisfy the requirement that new function definitions include docstrings. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The new helper function `_wrapped` is introduced without a docstring, and the suggestion directly addresses that style rule. This is a real violation in the final file state.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_info.py%0A%2A%2ALine%3A%2A%2A%2048%3A49%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20short%20docstring%20to%20this%20newly%20introduced%20helper%20function%20to%20satisfy%20the%20requirement%20that%20new%20function%20definitions%20include%20docstrings.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%2
 0implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_info.py%0A%2A%2ALine%3A%2A%2A%2048%3A49%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20short%20docstring%20to%20this%20newly%20introduced%20helper%20function%20to%20satisfy%20the%20requirement%20that%20new%20function%20definitions%20include%20docstrings.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%
 20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/chart/tool/test_get_chart_info.py
   **Line:** 48:49
   **Comment:**
   	*Custom Rule: Add a short docstring to this newly introduced helper function to satisfy the requirement that new function definitions include docstrings.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=474735ca1878c0925d1f51b57e5180b8e122c30413f562a55a276d122141526c&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=474735ca1878c0925d1f51b57e5180b8e122c30413f562a55a276d122141526c&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py:
##########
@@ -409,7 +412,86 @@ def test_serialize_chart_object_with_certification_fields(self):
 
         assert result is not None
         assert result.certified_by == "Data Team"
-        assert result.certification_details == "Verified Q1 2026 metrics"
+        assert result.certification_details == sanitize_for_llm_context(
+            "Verified Q1 2026 metrics"
+        )
+
+    def test_serialize_chart_object_sanitizes_chart_metadata_and_filters(self):
+        """serialize_chart_object sanitizes chart read-path content in place."""
+        from superset.mcp_service.chart.schemas import serialize_chart_object
+
+        chart = _make_mock_chart()
+        chart.description = "Show sales instructions"
+        chart.certification_details = "Verified by analytics"
+        chart.params = utils_json.dumps(
+            {
+                "datasource": "42__table",
+                "datasource_id": 42,
+                "datasource_type": "table",
+                "viz_type": "echarts_timeseries_bar",
+                "adhoc_filters": [
+                    {
+                        "expressionType": "SQL",
+                        "sqlExpression": "region = 'EMEA'",
+                    }
+                ],
+                "where": "country = 'BR'",
+                "time_range": "Last quarter",
+            }
+        )
+
+        result = serialize_chart_object(chart)
+
+        assert result is not None
+        assert result.slice_name == sanitize_for_llm_context("Test Chart")
+        assert result.description == sanitize_for_llm_context("Show sales instructions")
+        assert result.certification_details == sanitize_for_llm_context(
+            "Verified by analytics"
+        )
+        assert result.form_data is not None
+        assert result.form_data["datasource"] == "42__table"
+        assert result.form_data["where"] == sanitize_for_llm_context("country = 'BR'")
+        assert result.form_data["time_range"] == sanitize_for_llm_context(
+            "Last quarter"
+        )
+        assert result.filters is not None
+        assert result.filters.where == sanitize_for_llm_context("country = 'BR'")
+        assert result.filters.time_range == sanitize_for_llm_context("Last quarter")
+        assert result.filters.adhoc_filters[
+            0
+        ].sql_expression == sanitize_for_llm_context("region = 'EMEA'")
+
+    def test_generate_chart_form_data_response_is_sanitized(self):

Review Comment:
   **Suggestion:** Add an explicit return type annotation to this newly added test method (for example, `-> None`) so the new function has declared typing. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   This newly added test method also lacks an explicit return annotation. Given the project's typing rules for untyped definitions, the suggestion identifies a genuine violation.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_generate_chart.py%0A%2A%2ALine%3A%2A%2A%20464%3A464%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20this%20newly%20added%20test%20method%20%28for%20example%2C%20%60-%3E%20None%60%29%20so%20the%20new%20function%20has%20declared%20typing.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20co
 rrectness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_generate_chart.py%0A%2A%2ALine%3A%2A%2A%20464%3A464%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20to%20this%20newly%20added%20test%20method%20%28for%20example%2C%20%60-%3E%20None%60%29%20so%20the%20new%20function%20has%20declared%20typing.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20
 yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/chart/tool/test_generate_chart.py
   **Line:** 464:464
   **Comment:**
   	*Custom Rule: Add an explicit return type annotation to this newly added test method (for example, `-> None`) so the new function has declared typing.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=2657e86d88e73cf5feb71b43d049fc1d78b047860bbce77910441edab84585aa&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=2657e86d88e73cf5feb71b43d049fc1d78b047860bbce77910441edab84585aa&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py:
##########
@@ -226,6 +235,98 @@ def test_pop_kpi_uses_singular_metric(self):
         assert groupby == []
 
 
+class TestChartDataSanitization:
+    """Tests for chart read-path payload sanitization."""
+
+    def test_sanitize_chart_data_wraps_rows_summaries_and_csv(self):

Review Comment:
   **Suggestion:** Add explicit type hints to this new test method, including a `-> None` return annotation. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The new test method is missing an explicit `-> None` return annotation, which matches the custom typing rule described by the suggestion. This is a real violation in the current file.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_data.py%0A%2A%2ALine%3A%2A%2A%20241%3A241%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20hints%20to%20this%20new%20test%20method%2C%20including%20a%20%60-%3E%20None%60%20return%20annotation.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCod
 e Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_data.py%0A%2A%2ALine%3A%2A%2A%20241%3A241%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20hints%20to%20this%20new%20test%20method%2C%20including%20a%20%60-%3E%20None%60%20return%20annotation.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py
   **Line:** 241:241
   **Comment:**
   	*Custom Rule: Add explicit type hints to this new test method, including a `-> None` return annotation.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=6f8b484aef9f05965069d36733fec2eece23c5f06d7e593b3177fc59eb26577a&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=6f8b484aef9f05965069d36733fec2eece23c5f06d7e593b3177fc59eb26577a&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py:
##########
@@ -226,6 +235,98 @@ def test_pop_kpi_uses_singular_metric(self):
         assert groupby == []
 
 
+class TestChartDataSanitization:
+    """Tests for chart read-path payload sanitization."""
+
+    def test_sanitize_chart_data_wraps_rows_summaries_and_csv(self):
+        """ChartData helper should wrap user-controlled strings in read responses."""
+        chart_data = ChartData(
+            chart_id=7,
+            chart_name="Revenue by Region",
+            chart_type="bar",
+            columns=[],
+            data=[
+                {
+                    "region": "EMEA",
+                    "amount": 120,
+                    "url": "https://example.com/in-row-data",
+                    "schema": "customer-provided schema text",
+                },
+                {"region": "LATAM", "amount": 95},
+            ],
+            row_count=2,
+            total_rows=2,
+            summary="Two rows returned",
+            insights=["EMEA leads", "LATAM is second"],
+            data_quality={},
+            recommended_visualizations=[],
+            data_freshness=None,
+            performance=PerformanceMetadata(query_duration_ms=12, cache_status="miss"),
+            csv_data="region,amount\nEMEA,120\nLATAM,95\n",
+            format="csv",
+        )
+
+        result = _sanitize_chart_data_for_llm_context(chart_data)
+
+        assert result.chart_name == sanitize_for_llm_context("Revenue by Region")
+        assert result.summary == sanitize_for_llm_context("Two rows returned")
+        assert result.insights == [
+            sanitize_for_llm_context("EMEA leads"),
+            sanitize_for_llm_context("LATAM is second"),
+        ]
+        assert result.data[0]["region"] == sanitize_for_llm_context("EMEA")
+        assert result.data[0]["amount"] == 120
+        assert result.data[0]["url"] == sanitize_for_llm_context(
+            "https://example.com/in-row-data"
+        )
+        assert result.data[0]["schema"] == sanitize_for_llm_context(
+            "customer-provided schema text"
+        )
+        assert result.csv_data == sanitize_for_llm_context(
+            "region,amount\nEMEA,120\nLATAM,95\n"
+        )
+
+    def test_sanitize_chart_data_wraps_column_sample_values(self):

Review Comment:
   **Suggestion:** Add explicit type hints to this new test method, including a `-> None` return annotation. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The added test method does not include a `-> None` return annotation, so it violates the same explicit type-hint requirement as the first suggestion.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_data.py%0A%2A%2ALine%3A%2A%2A%20289%3A289%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20hints%20to%20this%20new%20test%20method%2C%20including%20a%20%60-%3E%20None%60%20return%20annotation.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCod
 e Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_data.py%0A%2A%2ALine%3A%2A%2A%20289%3A289%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20hints%20to%20this%20new%20test%20method%2C%20including%20a%20%60-%3E%20None%60%20return%20annotation.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/chart/tool/test_get_chart_data.py
   **Line:** 289:289
   **Comment:**
   	*Custom Rule: Add explicit type hints to this new test method, including a `-> None` return annotation.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=3507030ea644e01bd1a8ce303fc9f56064f129d2982414d6d086e442e65187cf&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=3507030ea644e01bd1a8ce303fc9f56064f129d2982414d6d086e442e65187cf&reaction=dislike'>πŸ‘Ž</a>



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39738:
URL: https://github.com/apache/superset/pull/39738#issuecomment-4340120746

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #39738:
URL: https://github.com/apache/superset/pull/39738#discussion_r3161164954


##########
tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py:
##########
@@ -340,6 +349,191 @@ async def test_performance_metadata(self):
         assert metadata.cache_status == "hit"
         assert len(metadata.optimization_suggestions) == 1
 
+
+class TestChartPreviewSanitization:
+    """Tests for chart preview read-path sanitization."""
+
+    def test_sanitize_chart_preview_wraps_ascii_and_alt_text(self):

Review Comment:
   **Suggestion:** Add an explicit return type annotation (`-> None`) to this newly added test method so new Python functions include type hints. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The new test method has no return type annotation, so it does not satisfy a rule requiring explicit type hints on new Python functions.
   The suggestion correctly identifies a real omission in the added code.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_preview.py%0A%2A%2ALine%3A%2A%2A%20356%3A356%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20%28%60-%3E%20None%60%29%20to%20this%20newly%20added%20test%20method%20so%20new%20Python%20functions%20include%20type%20hints.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20a
 nd%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_preview.py%0A%2A%2ALine%3A%2A%2A%20356%3A356%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20an%20explicit%20return%20type%20annotation%20%28%60-%3E%20None%60%29%20to%20this%20newly%20added%20test%20method%20so%20new%20Python%20functions%20include%20type%20hints.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20al
 l%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
   **Line:** 356:356
   **Comment:**
   	*Custom Rule: Add an explicit return type annotation (`-> None`) to this newly added test method so new Python functions include type hints.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=107210044422655232b81653cecb14a1693121dd547bfb0cecdefa6c8e7c23b5&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=107210044422655232b81653cecb14a1693121dd547bfb0cecdefa6c8e7c23b5&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py:
##########
@@ -317,6 +325,57 @@ def test_dashboard_serializer_restricted_user_redacts_data_model_metadata(
         assert result.charts[0].datasource_name is None
         assert result.native_filters[0].targets == []
 
+    @patch("superset.mcp_service.dashboard.schemas.user_can_view_data_model_metadata")
+    @patch("superset.mcp_service.utils.url_utils.get_superset_base_url")
+    def test_descriptive_fields_are_sanitized(
+        self,
+        mock_base_url,
+        mock_can_view_data_model_metadata,
+    ):

Review Comment:
   **Suggestion:** Add explicit type hints for all parameters and the return type on this newly added test method (including annotating it to return `None`). [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The added test method is missing parameter type annotations and an explicit `-> None` return annotation, so it does violate the stated type-hinting rule.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fdashboard%2Ftest_dashboard_schemas.py%0A%2A%2ALine%3A%2A%2A%20330%3A334%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20hints%20for%20all%20parameters%20and%20the%20return%20type%20on%20this%20newly%20added%20test%20method%20%28including%20annotating%20it%20to%20return%20%60None%60%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20corr
 ectness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fdashboard%2Ftest_dashboard_schemas.py%0A%2A%2ALine%3A%2A%2A%20330%3A334%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20hints%20for%20all%20parameters%20and%20the%20return%20type%20on%20this%20newly%20added%20test%20method%20%28including%20annotating%20it%20to%20return%20%60None%60%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%
 2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py
   **Line:** 330:334
   **Comment:**
   	*Custom Rule: Add explicit type hints for all parameters and the return type on this newly added test method (including annotating it to return `None`).
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=74891a297e26de987b501679b3159665374c88b5767555028f1c80b700f55f04&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=74891a297e26de987b501679b3159665374c88b5767555028f1c80b700f55f04&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py:
##########
@@ -0,0 +1,285 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Unit tests for the open_sql_lab_with_context MCP tool."""
+
+import importlib
+import sys
+import types
+from contextlib import nullcontext
+from unittest.mock import MagicMock, Mock, patch
+from urllib.parse import parse_qs, urlsplit
+
+from superset.mcp_service.sql_lab.schemas import OpenSqlLabRequest
+from superset.mcp_service.utils.sanitization import sanitize_for_llm_context
+
+
+def _force_passthrough_decorators() -> dict[str, types.ModuleType]:
+    """Force the MCP tool decorator to be a passthrough for unit tests."""
+
+    def _passthrough_tool(func=None, **kwargs):

Review Comment:
   **Suggestion:** Add explicit type annotations for `func`, `kwargs`, and the return type in this newly added helper to satisfy the typing requirement for new functions. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The helper is a newly added function and it lacks type annotations for both parameters and the return type. This matches the custom typing rule described in the suggestion.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fsql_lab%2Ftool%2Ftest_open_sql_lab_with_context.py%0A%2A%2ALine%3A%2A%2A%2034%3A34%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20annotations%20for%20%60func%60%2C%20%60kwargs%60%2C%20and%20the%20return%20type%20in%20this%20newly%20added%20helper%20to%20satisfy%20the%20typing%20requirement%20for%20new%20functions.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20co
 mments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fsql_lab%2Ftool%2Ftest_open_sql_lab_with_context.py%0A%2A%2ALine%3A%2A%2A%2034%3A34%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20explicit%20type%20annotations%20for%20%60func%60%2C%20%60kwargs%60%2C%20and%20the%20return%20type%20in%20this%20newly%20added%20helper%20to%20satisfy%20the%20typing%20requirement%20for%20new%20functions.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%
 20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py
   **Line:** 34:34
   **Comment:**
   	*Custom Rule: Add explicit type annotations for `func`, `kwargs`, and the return type in this newly added helper to satisfy the typing requirement for new functions.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=7b97b7b2ecabfc9ef43f4b67573627fa951c17f261f6614fcdfbb8950520fc30&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=7b97b7b2ecabfc9ef43f4b67573627fa951c17f261f6614fcdfbb8950520fc30&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py:
##########
@@ -35,9 +35,17 @@
     serialize_chart_summary,
     serialize_dashboard_object,
 )
+from superset.mcp_service.utils.sanitization import (
+    LLM_CONTEXT_CLOSE_DELIMITER,
+    LLM_CONTEXT_OPEN_DELIMITER,
+)
 from superset.utils.json import dumps as json_dumps
 
 
+def _wrapped(value: str) -> str:
+    return f"{LLM_CONTEXT_OPEN_DELIMITER}\n{value}\n{LLM_CONTEXT_CLOSE_DELIMITER}"

Review Comment:
   **Suggestion:** Add a short docstring to this newly introduced helper function so new function definitions include documentation. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The new helper function `_wrapped` has no docstring in the final file, so this suggestion accurately flags a real violation of the stated documentation rule.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fdashboard%2Ftest_dashboard_schemas.py%0A%2A%2ALine%3A%2A%2A%2045%3A46%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20short%20docstring%20to%20this%20newly%20introduced%20helper%20function%20so%20new%20function%20definitions%20include%20documentation.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
  | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fdashboard%2Ftest_dashboard_schemas.py%0A%2A%2ALine%3A%2A%2A%2045%3A46%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20short%20docstring%20to%20this%20newly%20introduced%20helper%20function%20so%20new%20function%20definitions%20include%20documentation.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20mi
 nimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/dashboard/test_dashboard_schemas.py
   **Line:** 45:46
   **Comment:**
   	*Custom Rule: Add a short docstring to this newly introduced helper function so new function definitions include documentation.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=3125c9a8229a469bc4067472f0a5941a532055b304489756f04e4112909453c9&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=3125c9a8229a469bc4067472f0a5941a532055b304489756f04e4112909453c9&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py:
##########
@@ -340,6 +349,191 @@ async def test_performance_metadata(self):
         assert metadata.cache_status == "hit"
         assert len(metadata.optimization_suggestions) == 1
 
+
+class TestChartPreviewSanitization:
+    """Tests for chart preview read-path sanitization."""
+
+    def test_sanitize_chart_preview_wraps_ascii_and_alt_text(self):
+        """ASCII previews should be wrapped while operational URLs stay raw."""
+        preview = ChartPreview(
+            chart_id=3,
+            chart_name="Regional Trend",
+            chart_type="line",
+            explore_url="http://localhost:8088/explore/?slice_id=3",
+            content=ASCIIPreview(ascii_content="North > South", width=20, height=5),
+            chart_description="Preview of line: Regional Trend",
+            accessibility=AccessibilityMetadata(
+                color_blind_safe=True,
+                alt_text="Preview of Regional Trend",
+                high_contrast_available=False,
+            ),
+            performance=PerformanceMetadata(query_duration_ms=8, cache_status="miss"),
+            format="ascii",
+            ascii_chart="North > South",
+            width=20,
+            height=5,
+        )
+
+        result = _sanitize_chart_preview_for_llm_context(preview)
+
+        assert result.chart_name == sanitize_for_llm_context("Regional Trend")
+        assert result.explore_url == "http://localhost:8088/explore/?slice_id=3"
+        assert result.chart_description == sanitize_for_llm_context(
+            "Preview of line: Regional Trend"
+        )
+        assert result.content.ascii_content == sanitize_for_llm_context("North > South")
+        assert result.ascii_chart == sanitize_for_llm_context("North > South")
+        assert result.accessibility.alt_text == sanitize_for_llm_context(
+            "Preview of Regional Trend"
+        )
+
+    def test_sanitize_chart_preview_wraps_vega_lite_data_values(self):
+        """Vega-Lite previews should wrap description and row string values."""
+        preview = ChartPreview(
+            chart_id=4,
+            chart_name="Category Share",
+            chart_type="pie",
+            explore_url="http://localhost:8088/explore/?slice_id=4",
+            content=VegaLitePreview(
+                specification={
+                    "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
+                    "description": "Pie chart for category share",
+                    "data": {
+                        "values": [
+                            {
+                                "category": "Retail",
+                                "url": "https://example.com/retail",
+                                "value": 10,
+                            },
+                            {"category": "Enterprise", "value": 20},
+                        ]
+                    },
+                }
+            ),
+            chart_description="Preview of pie: Category Share",
+            accessibility=AccessibilityMetadata(
+                color_blind_safe=True,
+                alt_text="Preview of Category Share",
+                high_contrast_available=False,
+            ),
+            performance=PerformanceMetadata(query_duration_ms=11, cache_status="miss"),
+            format="vega_lite",
+        )
+
+        result = _sanitize_chart_preview_for_llm_context(preview)
+        specification = result.content.specification
+
+        assert specification["$schema"] == (
+            "https://vega.github.io/schema/vega-lite/v5.json"
+        )
+        assert specification["description"] == sanitize_for_llm_context(
+            "Pie chart for category share"
+        )
+        assert specification["data"]["values"][0][
+            "category"
+        ] == sanitize_for_llm_context("Retail")
+        assert specification["data"]["values"][0]["url"] == sanitize_for_llm_context(
+            "https://example.com/retail"
+        )
+        assert specification["data"]["values"][0]["value"] == 10
+
+    def test_sanitize_chart_preview_leaves_non_mapping_vega_lite_data_unchanged(self):

Review Comment:
   **Suggestion:** Add a docstring to this newly added test method to satisfy the docstring requirement for new Python function definitions. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The added test method is missing a docstring. If the custom rule requires docstrings on new Python function definitions, this is a real violation in the current code.
   The suggestion matches the code exactly.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_preview.py%0A%2A%2ALine%3A%2A%2A%20440%3A440%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20docstring%20to%20this%20newly%20added%20test%20method%20to%20satisfy%20the%20docstring%20requirement%20for%20new%20Python%20function%20definitions.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%
 20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fchart%2Ftool%2Ftest_get_chart_preview.py%0A%2A%2ALine%3A%2A%2A%20440%3A440%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20docstring%20to%20this%20newly%20added%20test%20method%20to%20satisfy%20the%20docstring%20requirement%20for%20new%20Python%20function%20definitions.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20
 correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py
   **Line:** 440:440
   **Comment:**
   	*Custom Rule: Add a docstring to this newly added test method to satisfy the docstring requirement for new Python function definitions.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=5eb5307c15ca4fb94c747cdcac38b5bc8e3e6bac17fd9f83e930c2256b063fde&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=5eb5307c15ca4fb94c747cdcac38b5bc8e3e6bac17fd9f83e930c2256b063fde&reaction=dislike'>πŸ‘Ž</a>



##########
tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py:
##########
@@ -0,0 +1,285 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Unit tests for the open_sql_lab_with_context MCP tool."""
+
+import importlib
+import sys
+import types
+from contextlib import nullcontext
+from unittest.mock import MagicMock, Mock, patch
+from urllib.parse import parse_qs, urlsplit
+
+from superset.mcp_service.sql_lab.schemas import OpenSqlLabRequest
+from superset.mcp_service.utils.sanitization import sanitize_for_llm_context
+
+
+def _force_passthrough_decorators() -> dict[str, types.ModuleType]:
+    """Force the MCP tool decorator to be a passthrough for unit tests."""
+
+    def _passthrough_tool(func=None, **kwargs):
+        del kwargs
+        if func is not None:
+            return func
+        return lambda f: f
+
+    mock_mcp = MagicMock()
+    mock_mcp.tool = _passthrough_tool
+
+    mock_decorators = MagicMock()
+    mock_decorators.tool = _passthrough_tool
+
+    mock_api = MagicMock()
+    mock_api.mcp = mock_mcp
+
+    saved_modules: dict[str, types.ModuleType] = {}
+    for key in (
+        "superset_core.api",
+        "superset_core.api.mcp",
+        "superset_core.api.types",
+        "superset_core.mcp",
+        "superset_core.mcp.decorators",
+    ):
+        if key in sys.modules:
+            saved_modules[key] = sys.modules[key]
+
+    sys.modules["superset_core.api"] = mock_api
+    sys.modules["superset_core.api.mcp"] = mock_mcp
+    sys.modules["superset_core.mcp"] = mock_mcp
+    sys.modules["superset_core.mcp.decorators"] = mock_decorators
+    sys.modules.setdefault("superset_core.api.types", MagicMock())
+
+    return saved_modules
+
+
+def _restore_modules(saved_modules: dict[str, types.ModuleType]) -> None:
+    """Restore mocked decorator modules after each test import."""
+    for key in list(sys.modules.keys()):
+        if key.startswith(("superset_core.api", "superset_core.mcp")) or key.startswith(
+            "superset.mcp_service.sql_lab.tool"
+        ):
+            del sys.modules[key]
+    sys.modules.update(saved_modules)
+
+
+def _get_tool_module():

Review Comment:
   **Suggestion:** Add a return type annotation to this new function signature so the new function is fully typed. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? πŸ€” </b></summary>
   
   The function is newly introduced and has no return type annotation. That is a real violation of the typing requirement for new functions.
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fsql_lab%2Ftool%2Ftest_open_sql_lab_with_context.py%0A%2A%2ALine%3A%2A%2A%2079%3A79%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20return%20type%20annotation%20to%20this%20new%20function%20signature%20so%20the%20new%20function%20is%20fully%20typed.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | 
 [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fsql_lab%2Ftool%2Ftest_open_sql_lab_with_context.py%0A%2A%2ALine%3A%2A%2A%2079%3A79%0A%2A%2AComment%3A%2A%2A%0A%09%2ACustom%20Rule%3A%20Add%20a%20return%20type%20annotation%20to%20this%20new%20function%20signature%20so%20the%20new%20function%20is%20fully%20typed.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%
 20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py
   **Line:** 79:79
   **Comment:**
   	*Custom Rule: Add a return type annotation to this new function signature so the new function is fully typed.
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=d6acaed1bb0430714f52b45f423d3ff8bdaa286b2bbbdd69845df88e40ae98f0&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=d6acaed1bb0430714f52b45f423d3ff8bdaa286b2bbbdd69845df88e40ae98f0&reaction=dislike'>πŸ‘Ž</a>



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39738:
URL: https://github.com/apache/superset/pull/39738#issuecomment-4346166667

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers a full AI review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #39738:
URL: https://github.com/apache/superset/pull/39738#issuecomment-4356992277

   **Bito Automatic Review Skipped – PR Already Merged**<br/><br/>Bito scheduled an automatic review for this pull request, but the review was skipped because this PR was merged before the review could be run.<br/>No action is needed if you didn't intend to review it. To get a review, you can type `/review` in a comment and save it


-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #39738:
URL: https://github.com/apache/superset/pull/39738#discussion_r3161190548


##########
tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py:
##########
@@ -0,0 +1,285 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""Unit tests for the open_sql_lab_with_context MCP tool."""
+
+import importlib
+import sys
+import types
+from contextlib import nullcontext
+from unittest.mock import MagicMock, Mock, patch
+from urllib.parse import parse_qs, urlsplit
+
+from superset.mcp_service.sql_lab.schemas import OpenSqlLabRequest
+from superset.mcp_service.utils.sanitization import sanitize_for_llm_context
+
+
+def _force_passthrough_decorators() -> dict[str, types.ModuleType]:
+    """Force the MCP tool decorator to be a passthrough for unit tests."""
+
+    def _passthrough_tool(func=None, **kwargs):
+        del kwargs
+        if func is not None:
+            return func
+        return lambda f: f
+
+    mock_mcp = MagicMock()
+    mock_mcp.tool = _passthrough_tool
+
+    mock_decorators = MagicMock()
+    mock_decorators.tool = _passthrough_tool
+
+    mock_api = MagicMock()
+    mock_api.mcp = mock_mcp
+
+    saved_modules: dict[str, types.ModuleType] = {}
+    for key in (
+        "superset_core.api",
+        "superset_core.api.mcp",
+        "superset_core.api.types",
+        "superset_core.mcp",
+        "superset_core.mcp.decorators",
+    ):
+        if key in sys.modules:
+            saved_modules[key] = sys.modules[key]
+
+    sys.modules["superset_core.api"] = mock_api
+    sys.modules["superset_core.api.mcp"] = mock_mcp
+    sys.modules["superset_core.mcp"] = mock_mcp
+    sys.modules["superset_core.mcp.decorators"] = mock_decorators
+    sys.modules.setdefault("superset_core.api.types", MagicMock())
+
+    return saved_modules
+
+
+def _restore_modules(saved_modules: dict[str, types.ModuleType]) -> None:
+    """Restore mocked decorator modules after each test import."""
+    for key in list(sys.modules.keys()):
+        if key.startswith(("superset_core.api", "superset_core.mcp")) or key.startswith(
+            "superset.mcp_service.sql_lab.tool"
+        ):
+            del sys.modules[key]
+    sys.modules.update(saved_modules)
+
+
+def _get_tool_module():
+    """Import the tool module with passthrough decorators."""
+    saved_modules = _force_passthrough_decorators()
+    mod_name = "superset.mcp_service.sql_lab.tool.open_sql_lab_with_context"
+    saved_tool_modules: dict[str, object] = {}
+    for key in list(sys.modules.keys()):
+        if key.startswith("superset.mcp_service.sql_lab.tool"):
+            saved_tool_modules[key] = sys.modules.pop(key)
+    saved_modules.update(saved_tool_modules)
+    mod = importlib.import_module(mod_name)
+    return mod, saved_modules
+
+
+def _make_mock_ctx() -> MagicMock:
+    """Create a mock FastMCP context."""
+    return MagicMock()
+
+
+class TestOpenSqlLabWithContext:
+    """Regression coverage for sanitized SQL Lab read-path output."""
+
+    def test_sanitizes_direct_sql_and_title_in_url_and_response(self) -> None:
+        mod, saved_modules = _get_tool_module()
+        try:

Review Comment:
   **Suggestion:** `sys.modules` is mutated inside `_get_tool_module`, but `_get_tool_module()` is called before entering the `try/finally` cleanup block. If import fails, `_restore_modules` is never executed and the patched module state leaks into later tests, causing cascading and hard-to-debug failures. Move the `_get_tool_module()` call inside the `try` (or make `_get_tool_module` self-cleaning on error). [possible bug]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ MCP SQL Lab tests leak patched superset_core modules.
   - ⚠️ Later tests may see MagicMocks instead of real decorators.
   ```
   </details>
   <details>
   <summary><b>Steps of Reproduction βœ… </b></summary>
   
   ```mdx
   1. Introduce an import-time error in the tool module, e.g. add invalid syntax to
   `superset/mcp_service/sql_lab/tool/open_sql_lab_with_context.py` so that
   `importlib.import_module("superset.mcp_service.sql_lab.tool.open_sql_lab_with_context")`
   fails (see `_get_tool_module` at
   `tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py:79-89`).
   
   2. Run `pytest
   tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py`, which calls
   `mod, saved_modules = _get_tool_module()` before the `try/finally` in
   `test_sanitizes_direct_sql_and_title_in_url_and_response` at lines 100-103.
   
   3. During `_get_tool_module`, `_force_passthrough_decorators` at lines 31-66 patches
   `sys.modules["superset_core.api"]`, `sys.modules["superset_core.api.mcp"]`,
   `sys.modules["superset_core.api.types"]`, `sys.modules["superset_core.mcp"]`, and
   `sys.modules["superset_core.mcp.decorators"]` to MagicMocks and records any pre-existing
   modules in `saved_modules`, then `importlib.import_module` raises before
   `_get_tool_module` can return.
   
   4. Because the exception is thrown before entering the `try/finally` in each test method,
   `_restore_modules(saved_modules)` at lines 69-76 is never called, leaving `sys.modules` in
   a patched state; subsequent tests importing MCP-related code that depends on real
   `superset_core.mcp.decorators` (for example
   `superset/core/mcp/core_mcp_injection.py:282-295`, which imports and mutates
   `superset_core.mcp.decorators`) will see MagicMocks instead of the true decorators,
   causing confusing, cascading test failures unrelated to the original import error.
   ```
   </details>
   
   [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fsql_lab%2Ftool%2Ftest_open_sql_lab_with_context.py%0A%2A%2ALine%3A%2A%2A%20101%3A102%0A%2A%2AComment%3A%2A%2A%0A%09%2APossible%20Bug%3A%20%60sys.modules%60%20is%20mutated%20inside%20%60_get_tool_module%60%2C%20but%20%60_get_tool_module%28%29%60%20is%20called%20before%20entering%20the%20%60try%2Ffinally%60%20cleanup%20block.%20If%20import%20fails%2C%20%60_restore_modules%60%20is%20never%20executed%20and%20the%20patched%20module%20state%20leaks%20into%20later%20tests%2C%20causing%20cascading%20and%20hard-to-debug%20failures.%20Move%20the%20%60_get_tool_module%28%29%60%20call%20inside%20the%20%60try%60%20%28or%20make%20%60_get_tool_module%60%20self-cleaning%20on%20error%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%
 20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20tests%2Funit_tests%2Fmcp_service%2Fsql_lab%2Ftool%2Ftest_open_sql_lab_with_context.py%0A%2A%2ALine%3A%2A%2A%20101%3A102%0A%2A%2AComment%3A%2A%2A%0A%09%2APossible%20Bug%3A%20%60sys.modules%60%20is%20mutated%20inside%20%60_get_tool_module%60%2C%20but%20%60_get_tool_module%28%29%60%20is%20called%20before%20entering%20the%20%60try%2Ffinally%60%20cleanup%20block.%20If%20import%20fails%2C%20%60_restore_modules%6
 0%20is%20never%20executed%20and%20the%20patched%20module%20state%20leaks%20into%20later%20tests%2C%20causing%20cascading%20and%20hard-to-debug%20failures.%20Move%20the%20%60_get_tool_module%28%29%60%20call%20inside%20the%20%60try%60%20%28or%20make%20%60_get_tool_module%60%20self-cleaning%20on%20error%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/mcp_service/sql_lab/tool/test_open_sql_lab_with_context.py
   **Line:** 101:102
   **Comment:**
   	*Possible Bug: `sys.modules` is mutated inside `_get_tool_module`, but `_get_tool_module()` is called before entering the `try/finally` cleanup block. If import fails, `_restore_modules` is never executed and the patched module state leaks into later tests, causing cascading and hard-to-debug failures. Move the `_get_tool_module()` call inside the `try` (or make `_get_tool_module` self-cleaning on error).
   
   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.
   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>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=b2b1214cd94440438c820e8782af9420fcb6a0643a6b42222f59159d53dd5123&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F39738&comment_hash=b2b1214cd94440438c820e8782af9420fcb6a0643a6b42222f59159d53dd5123&reaction=dislike'>πŸ‘Ž</a>



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(mcp): sanitize read path output for LLM context [superset]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #39738:
URL: https://github.com/apache/superset/pull/39738#discussion_r3161078981


##########
superset/mcp_service/chart/tool/get_chart_preview.py:
##########
@@ -56,6 +57,77 @@
 logger = logging.getLogger(__name__)
 
 
+def _sanitize_preview_content_for_llm_context(content: dict[str, Any]) -> None:
+    """Wrap string-bearing preview content while preserving routing fields."""
+    content_type = content.get("type")
+
+    if content_type == "ascii":
+        content["ascii_content"] = sanitize_for_llm_context(
+            content.get("ascii_content"),
+            field_path=("content", "ascii_content"),
+        )
+        return
+
+    if content_type == "table":
+        content["table_data"] = sanitize_for_llm_context(
+            content.get("table_data"),
+            field_path=("content", "table_data"),
+        )
+        return
+
+    if content_type == "interactive":
+        content["html_content"] = sanitize_for_llm_context(
+            content.get("html_content"),
+            field_path=("content", "html_content"),
+        )
+        return
+
+    if content_type != "vega_lite":
+        return
+
+    specification = content.get("specification")
+    if not isinstance(specification, dict):
+        return
+
+    if "description" in specification:
+        specification["description"] = sanitize_for_llm_context(
+            specification.get("description"),
+            field_path=("content", "specification", "description"),
+        )
+
+    if (values := specification.get("data", {}).get("values")) is not None:
+        specification["data"]["values"] = sanitize_for_llm_context(
+            values,
+            field_path=("content", "specification", "data", "values"),
+            excluded_field_names=frozenset(),
+        )

Review Comment:
   In the Vega-Lite branch, `specification.get("data", {}).get("values")` assumes `specification["data"]` is a dict. If `data` is present but not a dict (valid Vega-Lite specs can use other shapes), this will raise an AttributeError. Guard with an `isinstance(data, dict)` check (and only then read/modify `values`) to keep preview sanitization robust.



##########
superset/mcp_service/utils/sanitization.py:
##########
@@ -31,9 +31,107 @@
 
 import html
 import re
+from typing import Any
 
 import nh3
 
+LLM_CONTEXT_OPEN_DELIMITER = "<UNTRUSTED-CONTENT>"
+LLM_CONTEXT_CLOSE_DELIMITER = "</UNTRUSTED-CONTENT>"
+LLM_CONTEXT_ESCAPED_OPEN_DELIMITER = "[ESCAPED-UNTRUSTED-CONTENT-OPEN]"
+LLM_CONTEXT_ESCAPED_CLOSE_DELIMITER = "[ESCAPED-UNTRUSTED-CONTENT-CLOSE]"
+LLM_CONTEXT_EXCLUDED_FIELD_NAMES = frozenset(
+    {
+        "cache_key",
+        "database",
+        "database_name",
+        "schema",
+        "schema_name",
+        "slug",
+        "url",
+        "urls",
+        "uuid",
+    }
+)
+
+
+def _normalize_field_name(field_name: str) -> str:
+    """Normalize a field name for exclusion matching."""
+    return field_name.strip().lower().replace("-", "_")
+
+
+def _wrap_llm_context_string(value: str) -> str:
+    """Wrap an untrusted string with explicit LLM-context delimiters."""
+    wrapped_prefix = f"{LLM_CONTEXT_OPEN_DELIMITER}\n"
+    wrapped_suffix = f"\n{LLM_CONTEXT_CLOSE_DELIMITER}"
+    if value.startswith(wrapped_prefix) and value.endswith(wrapped_suffix):
+        return value
+
+    escaped_value = value.replace(
+        LLM_CONTEXT_OPEN_DELIMITER,
+        LLM_CONTEXT_ESCAPED_OPEN_DELIMITER,
+    ).replace(
+        LLM_CONTEXT_CLOSE_DELIMITER,
+        LLM_CONTEXT_ESCAPED_CLOSE_DELIMITER,
+    )
+    return (
+        f"{LLM_CONTEXT_OPEN_DELIMITER}\n{escaped_value}\n{LLM_CONTEXT_CLOSE_DELIMITER}"
+    )
+
+
+def sanitize_for_llm_context(
+    value: Any,
+    *,
+    field_path: tuple[str, ...] = (),
+    excluded_field_names: frozenset[str] | None = None,
+) -> Any:
+    """
+    Recursively wrap user-controlled strings before placing them in LLM context.
+
+    Strings are wrapped in explicit untrusted-content delimiters unless the
+    current field name is part of the shared operational exclusion policy.
+    Container shapes and non-string values are preserved.
+    """
+    excluded_names = (
+        LLM_CONTEXT_EXCLUDED_FIELD_NAMES
+        if excluded_field_names is None
+        else excluded_field_names
+    )
+    normalized_exclusions = frozenset(
+        _normalize_field_name(field_name) for field_name in excluded_names
+    )
+
+    def _sanitize(current_value: Any, current_path: tuple[str, ...]) -> Any:
+        current_field_name = current_path[-1] if current_path else ""
+        if current_field_name and (
+            _normalize_field_name(current_field_name) in normalized_exclusions
+        ):
+            return current_value
+

Review Comment:
   `sanitize_for_llm_context` returns excluded fields unchanged without escaping the LLM delimiter strings. Since excluded operational fields like `database_name` can contain arbitrary user-provided text, a value containing `<UNTRUSTED-CONTENT>` / `</UNTRUSTED-CONTENT>` could spoof or break the boundary in LLM context. Consider still escaping delimiter sequences for excluded fields (while skipping wrapping), or splitting the policy into β€œdon’t wrap” vs β€œdon’t escape/transform” so operational fields remain usable but cannot inject delimiter tokens.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org