Skip to main content

Plugin to add a --json flag to the llm prompt command

Project description

llm-prompt-json

A plugin for LLM that adds a --json flag to the llm prompt command. This flag allows you to retrieve the response, conversation ID, and metadata as a JSON array, making it easy to integrate with tools like jq.

Built for llm version 0.28.

Installation

Install this plugin in the same environment as LLM:

llm install llm-prompt-json

Usage

Use the --json flag when running a prompt:

llm "say hello" --json

Example output:

[
  {
    "id": "01...",
    "model": "gpt-4o",
    "prompt": "say hello",
    "response": "Hello!",
    "conversation_id": "01..."
  }
]

Extracting the Conversation ID

Because the output is standard JSON, you can easily pipe it into jq to extract just the values you need. For example, to get the conversation_id:

llm "say hello" --json | jq -r '.[].conversation_id'

Compatibility

This plugin intercepts llm prompt dynamically, preventing the usual streamed output from polluting the JSON payload. It works correctly even if streaming is enabled or disabled, but it cannot be used alongside the --no-log flag since it relies on the internal LLM logs database to construct the complete metadata record.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_prompt_json-0.1.1.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_prompt_json-0.1.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file llm_prompt_json-0.1.1.tar.gz.

File metadata

  • Download URL: llm_prompt_json-0.1.1.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for llm_prompt_json-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b1c3efc1f3e25cd440fe0d86c4f4dbf31eff74b49f2e199dd9efa7d12049186b
MD5 2e868b4994c50b1ef74d815213b4731e
BLAKE2b-256 b95da46d7d65e7e2951fd2ca8753f17f48406001b4ffff8496b0aa566b8ec89c

See more details on using hashes here.

File details

Details for the file llm_prompt_json-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_prompt_json-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f2a9c35081e79e9d85c723cec5b92bbb6ffb6e603ee124b4e0f819963795abd6
MD5 bf92b86ac01b58d39df983927c432567
BLAKE2b-256 645aea172f7ac41c991433bed3f928eb18051cdabb031f608f0b72e2f7660c3b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page