Skip to content

wiring up jinja input marking #28249

Open

Description

@ngxson

Note: this issue is assigned, contributors should not take it

Jinja engine already support "input marking" to avoid special token injections in user messages, but the rest of the code base was not ready for it.

TODO:

  • add mtmd_tokenize_from_parts for fine-control per-segment tokenization (for example, one segment can be marked as parse_special, while other doesn't)
  • Refactor chat.cpp to output parts instead of a single string
  • Wire it up to server

Related issue: #24382

Activity

  1. ogwhic commented on Oct 12, 2026

    @ogwhic

    Is there a workaround for this until the implementation lands?

    Ran into it when trying to edit chat templates with an agent, each time the agent read the file and started reasoning about it it'd write the chat template tags and break. Injection problem too from a security perspective.

    Edit: This is a slightly separate problem. The model itself writing the tags as text, which may be unavoidable unless the distinction can be made between "special token with id" != "text matching ASCII representation of token with id". (edit edit: use markdown emphasis instead of XML delimiters, oh the irony)

  2. qdm12 commented on Oct 12, 2026

    @qdm12

    I did tell my ai to write a proxy server pointing it to this github issie, to fix the tag issue and it does work since then. It figured out a bunch of things and I honestly didn't care much on what was wrong as long as it worked, anyway it's a temp fix. Maybe point your agent to implement something like that?

  3. yudagua commented on Oct 21, 2026

    @yudagua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions