Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-4-20250514· AnthropicHugging Face LMArena Human Preference 140K

Write me a gbnf grammar. When a paragraph starts with " it should end at the next…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4.1-mini-2025-04-14’s answer.
  1. User

    Write me a gbnf grammar. When a paragraph starts with " it should end at the next occurance of ", so after that only a newline or <|end_of_sentence|> are allowed. When a paragraph starts with ( it should end at the next occurance of ), so after that only a newline or <|end_of_sentence|> are allowed. Should a paragraph start without " or (, it should not be allowed to contain " and (). Paragraph is any text that ends with either new line or <|end_of_sentence|>

  2. Claude Assistant

    Here's a GBNF grammar that implements your paragraph rules:

    root ::= paragraph*
    
    paragraph ::= quoted_paragraph | parenthetical_paragraph | regular_paragraph
    
    quoted_paragraph ::= "\"" quoted_content "\"" paragraph_end
    parenthetical_paragraph ::= "(" parenthetical_content ")" paragraph_end
    regular_paragraph ::= regular_content paragraph_end
    
    quoted_content ::= quoted_char*
    parenthetical_content ::= parenthetical_char*
    regular_content ::= regular_char+
    
    quoted_char ::= [^"\n] | "\\" ["]
    parenthetical_char ::= [^)\n] | "\\" [)]
    regular_char ::= [^"()\n]
    
    paragraph_end ::= "\n" | "<|end_of_sentence|>"
    

    This grammar defines:

    • quoted_paragraph: Starts with ", contains any characters except unescaped quotes and newlines, ends with " followed by a paragraph terminator
    • parenthetical_paragraph: Starts with (, contains any characters except unescaped parentheses and newlines, ends with ) followed by a paragraph terminator
    • regular_paragraph: Contains any characters except quotes, parentheses, and newlines, and must have at least one character
    • paragraph_end: Either a newline \n or the special token <|end_of_sentence|>

    The grammar allows for escaped quotes within quoted content and escaped parentheses within parenthetical content using backslash escaping. Regular paragraphs cannot contain quotes or parentheses at all, as specified in your requirements.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.