大型语言模型(LLM)依赖其上下文来生成下一组词元。在漫长的轨迹中,上下文会填充各种类型的组件:系统提示、过去的对话轮次、作用于检索文档的指令、工具响应或用户数据、约束允许输出的要求,以及推理链。上下文承载着丰富的结构,其中大部分对模型而言是隐式的,或者以 JSON 等并非为 LLM 消化而设计的格式进行编码。这是 LLM(尤其是规模较小的那些)脆弱且有时以意想不到的方式失败的主要原因之一。缺乏显式结构也可能被攻击者利用,例如以提示注入的形式。
为解决这一问题,我们开发了 LLMON(LLM Object Notation,发音为“lemon”),这是一种原生的 LLM 标记语言,用于向模型显式地传达结构和语义。语义连贯的组件用有意义的标签标记,并包裹在保留的特殊词元定界符中。数据模式(包括嵌套)以一种对因果语言模型而言无歧义的方式陈述。唯一 ID 使得能够指向上下文任意位置的特定指令,并将它们与应对其作用的数据负载绑定,类似于编程语言中调用函数并向其传递参数的方式。
今天,我们发布两个实验性预览模型,它们源自 Granite 4.1 基础模型,经过训练以消费和生成 LLMON 标记的文本:granite-4.1-3b-LLMON-preview 和 granite-4.1-8b-LLMON-preview。我们还发布了一个 GitHub 仓库,其中包含用于处理 LLMON 的工具包以及工作流和模板示例。
它带来的能力:
由于显式的指令/数据分离,隐藏在用户数据中的间接提示注入大多被 LLMON 模型忽略。在某些基准测试中,攻击成功率降至接近零,而常规的指令微调模型则有很高的概率被劫持。这是在保持与 Granite 4.1 Instruct 模型相对的一般能力的前提下实现的。
不相关的段落、旧的对话轮次和工具输出不会被拉入答案中,因为每个指令都绑定到其适用的确切数据上。
指令、数据和要求都有明确的标记,以便模型可以利用应用程序代码层面的结构和含义。您可以在 Mellea 中尝试一下,它通过自动将 LLM 调用转换为 LLMON 格式,原生支持 LLMON。
您不再需要担心强制 LLM 遵循 JSON 结构。使用我们的转换器可以将现有的 JSON 无损地转换为 LLMON。您还可以定义自己的结构及相关标签,并在 LLMON 模型之上微调 LoRA 以理解它。
为什么不是 JSON?
JSON 是为解析器设计的,而非为因果语言模型设计。词元化器不受限于遵守语法,结构由可能也出现在普通文本中的词元({, ", :)编码。对模型而言,文档内的引号和关闭字段的引号是相同的词元。对解析器而言清晰的转义规则,对模型来说只是统计模式。嵌套深度通过计算括号来编码,而 Transformer 在这一点上已知较弱,尤其是在长跨度情况下。
另一方面,LLMON 是一种类似 XML 的标记语言,其结构定界符是保留的特殊词元而非字符,因此结构和内容使用词汇表的不同部分。标签在每个区段的开头声明,且区段之间的边界是显式的。嵌套结构在本地声明,因此模型不需要在长跨度中跟踪层次结构。
由于大多数团队已经围绕 JSON 构建了管道,我们创建了转换工具和示例笔记本,以无损方式将 JSON 转换为 LLMON 并返回。
LLMON 与聊天模板有何关系?
LLMON 并不取代聊天模板,而是对其进行丰富。常规聊天模板告诉模型哪一部分属于哪个角色(系统、用户、助手),而 LLMON 则告诉模型每个组件的含义以及组件在角色内部和跨角色之间如何相互关联。
LLMON 预览版模型自带其专属的聊天模板,因此你可以构建与传递给任何聊天模型相同的消息列表,并像往常一样调用 apply_chat_template;它将渲染出如下所示的 LLMON 格式。唯一的区别是,现在对话轮次可以为其各部分命名,并将每一部分标记为 exec: True 或 False。标记为 True 的部分会被绑定到底部输出中的 exec 块中,该块说明了要运行哪个指令以及操作对象是什么;标记为 False 的部分仍会渲染到上下文中,但不会被任何内容引用。
messages = [ { "role": "user",
"instruction": [{ "value": "Write a short paragraph about", "exec": True }],
"data": [{ "value": "IBM Company", "exec": True }],
"requirement": [ {"value": "Use less than 10 words", "exec": True},
{"value": "Do not use commas", "exec": True}]
} ]
模型接收到的内容如下(为了便于阅读,此处添加了换行和缩进,因为模板本身不产生这些格式):
<|open|>instr<|:|>Ȗ<|close|>Write a short paragraph about<|open_end|>
<|open|>data<|:|>ä¦<|close|>IBM Company<|open_end|>
<|open|>req<|:|>Á¼<|close|>Use less than 10 words<|open_end|>
<|open|>req<|:|>¢¬<|close|>Do not use commas<|open_end|>
<|open|>exec<|:|>ÄÐ<|close|>
<|open|>exec<|.|>instruction<|close|>instr<|:|>Ȗ<|open_end|>
<|open|>exec<|.|>input<|close|>data<|:|>ä¦<|open_end|>
<|open|>exec<|.|>requirement<|close|>req<|:|>Á¼<|open_end|>
<|open|>exec<|.|>requirement<|close|>req<|:|>¢¬<|open_end|>
<|open|>exec<|.|>output<|close|>assistant<|:|>ãø<|open_end|>
<|open_end|>
<|open|>assistant<|:|>ãø<|close|>
这些两位数的块 ID 来自一个固定集合,该分词器将其编码为单个 token,因此无论使用哪个 ID,寻址一个块始终消耗两个 token。
角色仍然是一个单一的用户对话轮次,但其组件作为五个独立的、可寻址的块到达模型,并由第六个块(即 exec 块)绑定在一起,该块声明:在此数据上运行此指令,受这两个要求约束,并将答案放入此处命名的块中,也就是随后由模型填充的同一个助手块。传统的模板会将所有组件扁平化为一个字符串,并让模型自行推断哪部分是任务、哪部分是主题以及哪些是约束条件。
LLMON 如何应对提示注入攻击
间接提示注入是一种攻击类型,恶意指令隐藏在数据负载中,例如检索到的文档、工具响应或用户提供的数据。这正是 LLMON 的指令/数据分离设计旨在解决的问题。
我们将 LLMON 预览版与多个开源和闭源模型进行了比较。我们在 OPI 基准测试上进行了评估,该测试将注入内容置于经典 NLP 任务的数据中。我们采用了多种攻击策略。我们报告鲁棒性,定义为 1 − 攻击成功率:即模型未执行注入指令的攻击比例。
所有非 LLMON 模型都极易受到攻击,以高概率执行注入的指令。LLMON 几乎消除了该基准测试中的这一问题,与我们测试过的最佳前沿模型相比,避免了多 47% 的攻击,比最佳开源模型多避免了 95% 的攻击。我们在其他基准测试(ASB 和 StruQ)上也观察到了类似趋势。值得注意的是,这些基准测试针对的是静态间接提示注入的鲁棒性。指令/数据分离直接解决了此类攻击。我们正积极致力于提升对跨越多个对话轮次展开的自适应攻击的防御能力。
通用能力
安全性的提升并未以牺牲通用能力为代价。在标准基准测试类别中,LLMON 模型的表现与 Granite 4.1 Instruct 模型相当。
简而言之,如果您今天正在使用 Granite 4.1 3B 或 8B 进行实验,可以替换为 LLMON 预览版,并应能看到相当的通用性能以及强得多的提示注入抵抗能力。无需转换管道。只需命名轮次中的各部分(例如,如上例所示的指令、数据、要求)即可。随附的聊天模板会自动将这些转换为 LLMON 块。我们的 LLMON-converters 库更进一步:如果某个部分本身是结构化的,例如 JSON 文档,将其 LLMONizing 会保留其作为类型化、可单独寻址的块的结构,而不是作为一个不透明的字符串。
我们如何训练模型
这些模型以 Granite 4.1 基础检查点为起点,而非已发布的指令微调模型,因此 LLMON 行为是在后训练阶段习得的,而非叠加在现有的聊天格式之上。
LLMON 定义了六个分隔符,用于标记标签的起始和结束,并允许嵌套和锚定;它们作为保留的单令牌安装在分词器中。我们将一个传统的指令微调语料库重新序列化为 LLMON 格式:每个提示组件都成为其自己的可寻址块,且每个轮次都携带一个执行块,指明运行哪个指令、操作哪些输入以及输出去向何处。任务混合体是普通指令模型所见的(聊天、多轮对话、RAG、工具调用),这也是基准性能与常规微调模型保持接近的原因。此外,我们用诱饵指令和数据块增强数据,这些数据块存在于上下文中但故意未绑定,而目标输出保持不变。因此,模型学会了遵循执行块所规定的依赖关系并忽略其余部分。随后进行强化学习:五个连续的 GRPO 阶段涵盖多领域推理、RLHF、知识校准和数学,最后是一个基于千个从模型自身对注入尝试的响应中构建的在线偏好对的 DPO 阶段。
由此产生的特权规则源于这种布局而非附加的安全护栏:通过执行块访问的指令具有权威性,而任何作为输入(数据、文档、工具模式、工具结果)访问的内容都是用于读取的材料,而非要遵循的命令。此外,未在调用执行块中提及的指令和数据跨度会被忽略。这是一种习得的行为,而非强制保证。要了解这在 LLMON 模型的注意力层中如何体现,请尝试 Hugging Face Spaces 上的 LLMON 注意力可视化。
自带词汇表(ScienceWorld)
LLMON 不绑定于固定模式:您可以选择适合您领域的标签名称和结构,并微调适配器以读写它们。我们在 ScienceWorld 上展示了这一点,这是一个基于文本的基准测试,智能体通过一次发出一个命令并从模拟器接收分数来执行基础科学任务(如烧水)。我们定义了一个词汇表,捕捉了解决这些任务所涉及规划轨迹中的结构。该词汇表包括诸如 instr.task.goal、req.planning_policy.rule、data.state.room、data.state.inventory 和 assistant.next_action 等标签。我们用这些标签渲染了 ScienceWorld 参考解决方案的每一步,并在 LLMON 模型之上微调了一个 LoRA。训练后的模型随后进行未见的游戏,并用新词汇表写出其下一步动作。此笔记本逐步介绍了完整的工作流程,从转换参考轨迹到玩测试游戏并将适配器与未经训练的基座模型进行比较评分。有关工具调用智能体的另一个示例,请参阅此笔记本 。
今天尝试
这是一个实验性预览版,可用于探索和评估,但不适用于生产环境。
告诉我们你的发现:哪些功能有效,哪些出现了问题,以及你希望看到哪些用例。请在 GitHub Discussions 中发布。
LLMs rely on their context to generate the next set of tokens. Over a long trajectory, the context fills with numerous types of components: a system prompt, past conversation turns, instructions that act on retrieved documents, tool responses or user data, requirements constraining the allowed output, and reasoning chains. The context carries a rich structure, most of which is either implicit to the model or encoded in formats such as JSON that were not designed to be digested by LLMs. This is one of the main reasons LLMs, particularly those on the smaller end of the scale, are brittle and sometimes fail in unexpected ways. The lack of explicit structure can also be exploited by attackers, for example, in the form of prompt injections.
To address this, we developed LLMON (LLM Object Notation, pronounced “lemon”), an LLM-native markup language for explicitly communicating structure and semantics to the models. Semantically coherent components are marked with meaningful tags which are wrapped in reserved special-token delimiters. Data schemas, including nesting, are stated in a way that is unambiguous to a causal LLM. Unique IDs make it possible to point to specific instructions, which could reside anywhere in the context, and bind them to the data payloads they should act on, analogous to the way functions are called and arguments are passed to them in programming languages.
Today we are releasing two experimental preview models, derived from Granite 4.1 base models, trained to consume and generate LLMON-marked text: granite-4.1-3b-LLMON-preview and granite-4.1-8b-LLMON-preview . We are also releasing a GitHub repo, which includes a toolkit for working with LLMON and examples of workflows and templates.
What it enables:
Indirect prompt injections, hidden in user data, are mostly ignored by LLMON models due to explicit instruction/data separation. For some benchmarks, attack success rates drop to nearly zero, whereas regular instruction-tuned models get hijacked with high probability. This is achieved while maintaining general capability relative to Granite 4.1 Instruct models.
Unrelated passages, old chat turns, and tool outputs don’t get pulled into the answer because each instruction is bound to the exact data it applies to.
Instructions, data, and requirements are clearly marked so that their structure and meanings at the application’s code level can be leveraged by the model. Try it out in Mellea , which has native LLMON support enabled by automatically LLMONizing its LLM calls.
You no longer need to worry about forcing LLMs to observe JSON structure. Use our converters to turn existing JSON into LLMON without loss. You can also define your own structure and associated tags and tune a LoRA on top of the LLMON models to understand it.
Why not JSON?
JSON was designed for parsers, not for causal language models. The tokenizer is not constrained to respect the grammar, and structure is encoded by tokens ({, ", :) that may also appear in normal text. To a model, a quotation mark inside a document and a quotation mark that closes a field are the same token. Escaping rules that are clear to a parser are only statistical patterns to a model. Nesting depth is encoded by counting brackets, which transformers are known to be weak at, especially over long spans.
LLMON, on the other hand, is an XML-like markup whose structural delimiters are reserved special tokens rather than characters, so structure and content use separate parts of the vocabulary. Tags are stated at the beginning of each span, and the boundaries between spans are explicit. Nested structures are stated locally so the model does not need to keep track of the hierarchy over long spans.
Since most teams already have pipelines built around JSON, we created conversion tools and example notebooks that translate JSON to LLMON and back in a lossless manner.
How is LLMON related to chat templates?
LLMON does not replace chat templates; rather, it enriches them. Where regular chat templates tell the model which part belongs to which role (system, user, assistant), LLMON tells it what each component means and how components relate to each other, within and across roles.
The LLMON preview models ship with their own chat template, so you build the same messages list you would pass to any chat model and call apply_chat_template as usual; it renders the LLMON shown below. The only difference is that a turn can now name its parts and mark each one exec : True or False . A part marked True is bound into the exec block at the bottom of the rendered output, which states which instruction to run and what it operates on; a part marked False is still rendered into the context but is referenced by nothing.
messages = [ { "role": "user",
"instruction": [{ "value": "Write a short paragraph about", "exec": True }],
"data": [{ "value": "IBM Company", "exec": True }],
"requirement": [ {"value": "Use less than 10 words", "exec": True},
{"value": "Do not use commas", "exec": True}]
} ]
Which the model receives as the following (with newlines and indentation added here for readability, as the template emits none):
<|open|>instr<|:|>Ȗ<|close|>Write a short paragraph about<|open_end|>
<|open|>data<|:|>ä¦<|close|>IBM Company<|open_end|>
<|open|>req<|:|>Á¼<|close|>Use less than 10 words<|open_end|>
<|open|>req<|:|>¢¬<|close|>Do not use commas<|open_end|>
<|open|>exec<|:|>ÄÐ<|close|>
<|open|>exec<|.|>instruction<|close|>instr<|:|>Ȗ<|open_end|>
<|open|>exec<|.|>input<|close|>data<|:|>ä¦<|open_end|>
<|open|>exec<|.|>requirement<|close|>req<|:|>Á¼<|open_end|>
<|open|>exec<|.|>requirement<|close|>req<|:|>¢¬<|open_end|>
<|open|>exec<|.|>output<|close|>assistant<|:|>ãø<|open_end|>
<|open_end|>
<|open|>assistant<|:|>ãø<|close|>
The two-character block IDs are drawn from a fixed set that this tokenizer encodes as single tokens, so addressing a block always costs two tokens regardless of which ID is drawn.
The role is still a single user turn, but its components reach the model as five separate addressable blocks, bound together by a sixth (the exec block) that states: run this instruction, on this data, subject to these two requirements, and put the answer in the block named here, which is the same assistant block the model then fills. A conventional template would have flattened all components into one string and left the model to infer which part was the task, which was the subject, and which were constraints.
How LLMON addresses prompt injection attacks
Indirect prompt injection is a type of attack where a malicious instruction is hidden in a data payload, such as a retrieved document, a tool response, or user-provided data. This is the problem LLMON’s instruction/data separation is designed to address.
We compared the LLMON previews against several open-source and closed-source models. We evaluated on the OPI benchmark, which places the injection in the data of classic NLP tasks. Several attack strategies are employed. We report robustness, defined as 1 − attack success rate: the share of attacks where the model does not carry out the injected instruction.
All non-LLMON models are highly susceptible, carrying out the injected instructions with high probability. LLMON practically eliminates the problem on this benchmark, avoiding 47% more attacks relative to the best frontier model that we tested, and 95% more than the best open-source model. We observe similar trends on other benchmarks ( ASB and StruQ ). It is worth noting that these benchmarks test robustness to static indirect prompt injections. The instruction/data separation directly addresses this type of attack. We are actively working on also improving adaptive attacks which unfold over many chat turns.
General capability
Safety gains don’t come at the expense of general capability. Across standard benchmark categories, the LLMON models perform on par with the Granite 4.1 Instruct models.
In short, if you’re experimenting with Granite 4.1 3B or 8B today, you can swap in the LLMON preview and should see comparable general performance with much stronger resistance to prompt injection. No conversion pipeline is required. Naming the turn's parts (e.g., instruction, data, requirement as in the example above) is enough. The shipped chat template turns those into LLMON blocks for you. Our LLMON-converters library goes one level deeper: if a part is itself structured, such as a JSON document, LLMONizing it preserves that structure as typed, individually addressable blocks, instead of one opaque string.
How we trained the models
The models start from Granite 4.1 base checkpoints rather than the released instruct models, so LLMON behavior is learned during post-training rather than layered on an existing chat format.
LLMON defines six delimiters that mark the start and end of tags and allow nesting and anchoring; they are installed in the tokenizer as reserved single tokens. We re-serialized a conventional instruction-tuning corpus into LLMON: every prompt component becomes its own addressable block, and each turn carries an execution block naming which instruction to run, which inputs it operates on, and where the output goes. The task mix is the one a normal instruct model sees (chat, multi-turn, RAG, tool calling), which is why benchmark performance stays close to the conventionally tuned model. In addition, we augment the data with decoy instructions and data blocks that are present in context but deliberately left unbound, while the target output is unchanged. So the model learns to follow the dependencies dictated by the execution block and ignore the rest. Reinforcement learning follows: five sequential GRPO stages spanning multi-domain reasoning, RLHF, knowledge calibration, and math, followed by a final DPO stage on a thousand on-policy preference pairs built from the model’s own responses to injection attempts.
The resulting privilege rule falls out of this layout rather than an added guardrail: an instruction reached through an execution block is authoritative, while anything reached as input (data, documents, tool schemas, tool results) is material to read, not a command to follow. Furthermore, instructions and data spans that are not called on in the execution block are ignored. This is a learned behavior, not an enforced guarantee. To see how this plays out in the attention layers of a LLMON model, try the LLMON Attention Visualization on Hugging Face Spaces.
Bring your own vocabulary (ScienceWorld)
LLMON is not tied to a fixed schema: you can choose tag names and structure that fit your domain and fine-tune an adapter to read and write them. We demonstrate this on ScienceWorld, a text-based benchmark where an agent carries out elementary science tasks (such as boiling water) by issuing one command at a time and receiving a score from the simulator. We defined a vocabulary capturing the structure in the planning trajectories involved in solving these tasks. The vocabulary includes tags such as instr.task.goal , req.planning_policy.rule , data.state.room , data.state.inventory and assistant.next_action . We rendered every step of ScienceWorld's reference solutions with these tags and tuned a LoRA on top of a LLMON model. The trained model then plays held-out games and writes its next action in the new vocabulary. This notebook walks through the full workflow, from converting reference trajectories to playing the test games and scoring the adapter against the untrained base model. Another example for tool-calling agents can be found in this notebook .
Try it today
This is an experimental preview, ready for exploration and evaluation but not for production.
Tell us what you find: what worked, what broke, and which use cases you’d like to see. Post it in GitHub Discussions.
首次收录 · 2026-11-13 · 10.81 分