Metadata-Version: 2.4
Name: llm-prompt-json
Version: 0.1.1
Summary: Plugin to add a --json flag to the llm prompt command
Author-email: Thomas Hughes <irthomasthomas@gmail.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/irthomasthomas/llm-prompt-json
Project-URL: Changelog, https://github.com/irthomasthomas/llm-prompt-json/releases
Project-URL: Issues, https://github.com/irthomasthomas/llm-prompt-json/issues
Classifier: License :: OSI Approved :: Apache Software License
Description-Content-Type: text/markdown
Requires-Dist: llm

# llm-prompt-json

A plugin for [LLM](https://llm.datasette.io/) 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:

```bash
llm install llm-prompt-json
```

## Usage

Use the `--json` flag when running a prompt:

```bash
llm "say hello" --json
```

Example output:

```json
[
  {
    "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`:

```bash
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.
