Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Force LLMs to print JSON only #3

Merged
merged 1 commit into from
Jul 20, 2024

Conversation

knqyf263
Copy link
Contributor

@knqyf263 knqyf263 commented Jul 19, 2024

Description

I tested vexllm with Anthropic Claude 3.5 Sonnet and faced the following error.

$ vexllm generate python.json .trivyignore --hint-unused-commands=git,wget,curl,apt,apt-get --llm anthropic
Based on the provided information and hints, I can determine that all the vulnerabilities related to Git can be considered negligible for this specific container image. Here's the analysis:

\```json
{
    "CVE-2024-32002": {"confidence": 0.9, "reason": "This vulnerability affects Git, which is listed as an unused command in the container image. The risk of exploitation is minimal as Git operations are not expected to be performed within this Python container."},
    "CVE-2023-25652": {"confidence": 0.9, "reason": "This Git vulnerability is negligible as Git is listed as an unused command in the container. The `git apply` command is unlikely to be executed in a Python runtime environment."},
    "CVE-2023-29007": {"confidence": 0.9, "reason": "This vulnerability affects Git submodule operations, which are not relevant in a Python container image where Git is listed as an unused command."},
    "CVE-2024-32004": {"confidence": 0.9, "reason": "This Git vulnerability relates to cloning local repositories, which is not a typical operation in a Python runtime environment. Git is also listed as an unused command in this container."},
    "CVE-2024-32465": {"confidence": 0.9, "reason": "This additional Git RCE vulnerability is negligible as Git operations, including working with repositories, are not expected in this Python container image where Git is listed as unused."}
}
\```

The confidence level is high (0.9) for all these vulnerabilities because:

1. Git is explicitly mentioned in the list of unused commands for this container image.
2. The container image is specifically for Python (python:3.12.4), which typically doesn't involve Git operations in its runtime environment.
3. These vulnerabilities require specific Git operations to be exploited, which are unlikely to occur in a Python runtime container.

It's important to note that while these vulnerabilities are present in the scan results, they pose minimal risk in the context of this specific Python container image, given that Git is not expected to be used.
time=2024-07-19T15:35:38.800+04:00 level=ERROR msg=Error error="unparsable JSON output from LLM: invalid character 'B' looking for beginning of value: \"Based on the provided information and hints, I can determine that all the vulnerabilities related to Git can be considered negligible for this specific container image. Here's the analysis:\\n\\n```json\\n{\\n    \\\"CVE-2024-32002\\\": {\\\"confidence\\\": 0.9, \\\"reason\\\": \\\"This vulnerability affects Git, which is listed as an unused command in the container image. The risk of exploitation is minimal as Git operations are not expected to be performed within this Python container.\\\"},\\n    \\\"CVE-2023-25652\\\": {\\\"confidence\\\": 0.9, \\\"reason\\\": \\\"This Git vulnerability is negligible as Git is listed as an unused command in the container. The `git apply` command is unlikely to be executed in a Python runtime environment.\\\"},\\n    \\\"CVE-2023-29007\\\": {\\\"confidence\\\": 0.9, \\\"reason\\\": \\\"This vulnerability affects Git submodule operations, which are not relevant in a Python container image where Git is listed as an unused command.\\\"},\\n    \\\"CVE-2024-32004\\\": {\\\"confidence\\\": 0.9, \\\"reason\\\": \\\"This Git vulnerability relates to cloning local repositories, which is not a typical operation in a Python runtime environment. Git is also listed as an unused command in this container.\\\"},\\n    \\\"CVE-2024-32465\\\": {\\\"confidence\\\": 0.9, \\\"reason\\\": \\\"This additional Git RCE vulnerability is negligible as Git operations, including working with repositories, are not expected in this Python container image where Git is listed as unused.\\\"}\\n}\\n```\\n\\nThe confidence level is high (0.9) for all these vulnerabilities because:\\n\\n1. Git is explicitly mentioned in the list of unused commands for this container image.\\n2. The container image is specifically for Python (python:3.12.4), which typically doesn't involve Git operations in its runtime environment.\\n3. These vulnerabilities require specific Git operations to be exploited, which are unlikely to occur in a Python runtime container.\\n\\nIt's important to note that while these vulnerabilities are present in the scan results, they pose minimal risk in the context of this specific Python container image, given that Git is not expected to be used.\""
Exiting.

It seems like Claude prints its explanation in addition to the JSON content.

Signed-off-by: knqyf263 <knqyf263@gmail.com>
@knqyf263 knqyf263 mentioned this pull request Jul 19, 2024
Copy link
Owner

@AkihiroSuda AkihiroSuda left a comment

Choose a reason for hiding this comment

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

Thanks

@@ -168,6 +168,7 @@ If you find neglible vulnerabilities, print a JSON map formatted and indented as
systemPrompt += "* `confidence` (0.0-1.0): higher value if you are confident with the answer.\n"
systemPrompt += "* `reason`: the reason why you think the vulnerability is negligible. Should be unique, descriptive, and in 2 or 3 sentences.\n"
systemPrompt += "Do not include non-negligible vulnerabilities in the result.\n"
systemPrompt += "Only print a valid JSON.\n"
Copy link
Owner

Choose a reason for hiding this comment

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

llms.WithJSONMode() isn't enough?
Maybe this should be reported to https://github.com/tmc/langchaingo/issues

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OpenAI supports JSON mode, but I didn't find it in Anthoropic.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@AkihiroSuda AkihiroSuda merged commit 42970fb into AkihiroSuda:master Jul 20, 2024
3 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants