vllm - 💡(How to fix) Fix [Feature]: Support Structured Output with Batched Prompts via OpenAI-Compatible API [1 comments, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vllm-project/vllm#37976Fetched 2026-04-08 01:22:18
View on GitHub
Comments
1
Participants
1
Timeline
4
Reactions
4
Participants
Timeline (top)
closed ×1commented ×1labeled ×1renamed ×1
RAW_BUFFERClick to expand / collapse

🚀 The feature, motivation and pitch

Currently, vLLM supports batching prompts via the OpenAI compatible completions API (e.g., sending a list of prompts in a single request using curl). However I did not find any support for combining structured output (e.g., JSON schema) with batched chat compilations prompts through the OpenAI, compatible API using curl.

So I would please ask to add support for structured output with batched prompts in the OpenAI compatible API.

I would be happy to contribute to this feature and help improve vLLM if you find this useful.

Alternatives

No response

Additional context

No response

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

extent analysis

Fix Plan

To add support for structured output with batched prompts in the OpenAI compatible API, we need to modify the API endpoint to accept and process JSON schema with batched chat compilation prompts.

Steps to Implement the Fix

  • Modify the API endpoint to accept a JSON body with a list of prompts and a schema definition.
  • Update the API handler to parse the JSON body and extract the prompts and schema.
  • Use a library like jsonschema to validate the schema and ensure it conforms to the expected structure.
  • Process the batched prompts using the validated schema and return the structured output.

Example Code

import json
from jsonschema import validate

# Define the expected schema
schema = {
    "type": "object",
    "properties": {
        "prompts": {"type": "array", "items": {"type": "string"}},
        "schema": {"type": "object"}
    },
    "required": ["prompts", "schema"]
}

# API endpoint handler
def handle_batched_prompts(request):
    data = json.loads(request.body)
    validate(instance=data, schema=schema)
    prompts = data["prompts"]
    schema_def = data["schema"]
    # Process the batched prompts using the schema
    output = []
    for prompt in prompts:
        # Compile the prompt using the schema
        compiled_prompt = compile_prompt(prompt, schema_def)
        output.append(compiled_prompt)
    return {"output": output}

# Compile a single prompt using the schema
def compile_prompt(prompt, schema_def):
    # Implement the compilation logic here
    pass

Verification

To verify the fix, send a curl request to the modified API endpoint with a JSON body containing a list of prompts and a schema definition. The response should contain the structured output with the compiled prompts.

curl -X POST \
  http://example.com/api/batched-prompts \
  -H 'Content-Type: application/json' \
  -d '{"prompts": ["prompt1", "prompt2"], "schema": {"key": "value"}}'

Extra Tips

  • Ensure that the schema definition is properly validated to prevent errors during processing.
  • Consider adding error handling to handle cases where the schema is invalid or the prompts cannot be compiled.
  • Use a robust JSON schema validation library to ensure that the schema conforms to the expected structure.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING