Skip to content

Blacklist control characters in JSON string grammars #1259

Closed
@jndiogo

Description

@jndiogo

This llama.cpp PR fixed a random problem that I've observed in the past but never been able to reproduce:

ggml-org/llama.cpp#5888

The problem happens because the string definition in the JSON grammar doesn't exclude emitting raw \n, \r, etc. A model can thus produce a string split into multiple lines, which is not valid JSON.

File llama_cpp/llama_grammar.py needs the string grammar definition fixed in several places:

  • At the JSON_GBNF definition and others that have a string rule, like JSON_ARR_GBNF, etc.
  • At the string definition inside PRIMITIVE_RULES.

It's a single line change in the above PR.

Regards

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions