Skip to content

fix(web-app-ai-sensitive-data-scanner): render scan findings instead of raw json - #533

Merged
LukasHirt merged 1 commit into
mainfrom
fix-ai-sensitive-data-scanner-formatted-output
Jul 27, 2026
Merged

fix(web-app-ai-sensitive-data-scanner): render scan findings instead of raw json#533
LukasHirt merged 1 commit into
mainfrom
fix-ai-sensitive-data-scanner-formatted-output

Conversation

@LukasHirt

Copy link
Copy Markdown
Collaborator

Summary

  • The LLM proxy requests response_format: { type: 'json_object' }, but in practice the model frequently wraps its JSON response in a markdown code fence (```json ... ```) anyway. parseLlmResponse in useScanner.ts called JSON.parse directly on the raw content, so the fenced response failed to parse and the entire fenced blob (including the ``` fences) fell through to the narrative fallback, which the component renders verbatim as preformatted text — producing the "raw JSON dumped in a code fence" bug shown in the issue screenshot.
  • Fixed parseLlmResponse to:
    1. Strip a leading/trailing markdown code fence (```json ... ``` or bare ``` ... ```) before attempting to parse.
    2. If that still fails, fall back to extracting the substring between the first { and the last } (handles cases where the model adds leading/trailing prose around the JSON object).
    3. Only fall back to storing the raw response as narrative if none of the above yield a valid { findings: [...] } payload — preserving the existing plain-text fallback behavior for genuinely non-JSON responses.
  • No changes to the component's rendering logic — ScanResultsModal.vue's existing findings-list rendering (icon + category label + excerpt) was already correct; the bug was purely in parsing.

Test plan

  • Added packages/web-app-ai-sensitive-data-scanner/tests/unit/composables/useScanner.spec.ts covering: plain JSON, ```json fenced JSON, bare ``` fenced JSON, JSON with surrounding prose, and genuine non-JSON prose (narrative fallback).
  • pnpm --filter web-app-ai-sensitive-data-scanner test:unit — all tests pass (24/24, including existing ScanResultModal.spec.ts).
  • pnpm --filter web-app-ai-sensitive-data-scanner check:types — passes.
  • pnpm --filter web-app-ai-sensitive-data-scanner lint — passes.

Closes #531

🤖 Generated with Claude Code

…of raw json

Signed-off-by: Lukas Hirt <info@hirt.cz>
@LukasHirt
LukasHirt requested a review from a team as a code owner July 27, 2026 11:37
@kw-security

kw-security commented Jul 27, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@LukasHirt LukasHirt self-assigned this Jul 27, 2026
@LukasHirt
LukasHirt merged commit fadfdd1 into main Jul 27, 2026
34 checks passed
@LukasHirt
LukasHirt deleted the fix-ai-sensitive-data-scanner-formatted-output branch July 27, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ai-sensitive-data-scanner: output is not formatted

3 participants