gemma4_required_grammar.h

src/inference/gemma4_required_grammar.h

@file gemma4_required_grammar.h @brief Root-rule patch for the Gemma 4 tool_choice=REQUIRED grammar (v2.14.6).

Owners: @tvanfossen

patch_gemma4_required_root

std::string entropic::patch_gemma4_required_root(const std::string &gbnf)

Rewrite a Gemma 4 REQUIRED grammar's root to the f072b10371 shape.

src/inference/gemma4_required_grammar.h:100

Show on the map →

Called by SCENARIO, TEST_CASE, tool_grammar_for

Calls gbnf_root_line, gbnf_root_line_offset, gemma4_required_root_fixed_shape, gemma4_required_root_prefix_shape

Source · 9 lines
inline std::string patch_gemma4_required_root(const std::string& gbnf) {
    std::string out = gbnf;
    const std::string old_line = gemma4_required_root_prefix_shape();
    if (gbnf_root_line(gbnf) == old_line) {
        out.replace(gbnf_root_line_offset(gbnf), old_line.size(),
                    gemma4_required_root_fixed_shape());
    }
    return out;
}
Activity · 5 steps
lines 101–101std::string out = gbnf;lines 102–102const std::string old_line = gemma4_required_root_prefix_shape();lines 103–103◇ if (gbnf_root_line(gbnf) == old_line)lines 104–105out.replace(gbnf_root_line_offset(gbnf), old_line.size(), gemma4_required_root_fixed_shape());lines 107–107return out;

Requirements

REQ-INFER-008