response_format
field in the request like {"type": "grammar", "grammar": <your BNF grammar string> }
.
For best results, we still recommend that you do some prompt engineering and describe the desired output to the model to guide decision-making.
llama-v3p1-405b-instruct
, but all fireworks models support this feature.
nonterminal ::= sequence...
.
Consider an example of a small chess notation grammar:
move
, castle
, or check-mate
.
Terminals are actual characters (code points). They can be specified as a sequence like "1"
or "O-O"
or as ranges like [1-9]
or [NBKQR]
.
hiragana ::= [ぁ-ゟ]
, or with escapes: 8-bit (\xXX
), 16-bit (\uXXXX
) or 32-bit (\UXXXXXXXX
).
Character ranges can be negated with ^
:
.
symbol matches any character:
"1. " move " " move "\n"
, the "1. "
must come before the first move
, etc.
Alternatives, denoted by |
, give different sequences that are acceptable. For example, in move ::= pawn | nonpawn | castle
, move
can be a pawn
move, a nonpawn
move, or a castle
.
Parentheses ()
can be used to group sequences, which allows for embedding alternatives in a larger rule or applying repetition and optional symbols (below) to a sequence.
*
after a symbol or sequence means that it can be repeated zero or more times.+
denotes that the symbol or sequence should appear one or more times.?
makes the preceding symbol or sequence optional.#
:
|
will continue the current rule, even outside of parentheses.
root
rule always defines the starting point of the grammar. In other words, it specifies what the entire output must match.