xgrammar icon indicating copy to clipboard operation
xgrammar copied to clipboard

Repeated properties in vllm + xgrammar

Open denadai2 opened this issue 11 months ago • 1 comments

Is it normal that constrained properties could be repeated a lot?

from pydantic import BaseModel
class EpisodeGuestExtractionResponse(BaseModel):
    guests: List[str]

This is not a valid json: :/

{ "guests": ["David Farrier", "Monica Padman] }  (no guests)  { " 

  , 
  "guests" 
  , 
  "guests" 
  , 
  "guests" 
  , 
  "guests" 
  , 
  "guests" 
  , 
  "guests" 
  , 
  "guests" 

thx

denadai2 avatar Jan 29 '25 22:01 denadai2

Hi @denadai2 , thanks for reporting this issue! Sorry for the late response because I was occupied with some paper-related work.

Your output still seems to be valid JSON, but just its content is not expected. One possible reason for that is you may not describe the output structure in the prompt, but only rely on constraint decoding. This may not work well because LLM is not aware of the constraint. If this is the case, you can describe the structure in the prompt, say, "output a json object that contains a key 'guests' with a value that is a list of strings". That is helpful in practice.

Otherwise, could you provide your specific model and prompt? I can dig into that to see what the problem is.

Ubospica avatar Feb 12 '25 01:02 Ubospica