authoring module builds a proposed term list for you and makes sure nothing in it is trusted until a person says so. It is a side tool. It writes config for a deployment, and nothing imports it when the index runs.
In these examples the documents are Vietnamese, the source language, and the translator turns them into English, the target language. The candidates and the glossary keys are Vietnamese terms found in the source text. The en: field holds the English each one must become.
How a term list is built
1
Find candidates
The builder does not ask a model about every word. It first finds candidates with patterns: acronyms and runs of capitalized words. A candidate must appear in at least
min_count passages (default 2), so one-off words are skipped. The list is capped at max_terms (default 90).The patterns find source-language terms only. The default patterns also accept Đ, but cover only plain capital letters otherwise, so a term that starts with an accented capital such as Ủy Ban is missed. A lowercase domain word is never proposed unless you add a pattern.2
Let the agent decide each term
The agent is headless Claude Code (
claude --bare) with only the Read and Edit tools, plus the guarded search tool when search is on. Its model is served by a gateway you run. It reads candidates.txt and document_chunks.txt, decides each term, and appends entries to lexicon_out.yaml.3
Make the answer safe
Code repairs the agent’s YAML (for example an unquoted colon), drops terms nobody asked about, and caps confidence. A
high confidence stays only if a search for the term was logged, or the documents spell the term out, as in “Kế hoạch kinh doanh (KHKD)”. Otherwise it becomes medium. A term with no English is marked low and left for a person.4
Approve
Every entry is written with
status: proposed. A person reads the file and approves what they trust. The translator’s gate then enforces the approved terms.Proposed and approved terms
The web search is guarded
The agent may look up public terms on the web, but a query may only be a term: at most 4 words and 40 characters, on one line. Code enforces the rule, not the prompt. A model that tries to paste a passage into a search getsREFUSED, and the query never reaches the search provider.
An accepted query is sent to Tavily (api.tavily.com) with the key from the variable named in the config, which defaults to TAVILY_SEARCH_API. That is a network call. Every query is logged, and the log is how high confidence is earned. Search is off by default in the tutorial config.
Run it
The builder needs theclaude CLI on your path, a model endpoint, and a glossary_builder: section in your ladygraph.yaml.
1
Check the setup
doctor checks the claude CLI, that the endpoint answers with your key, that it serves the engine you configured, and that the search key is set. It sends no model request.2
Preview the candidates
--texts FILE... instead of --source to read plain text or markdown files.3
Build
--out, the file goes to the output: path in the config, which is relative to the folder you run the command from.4
Approve
--terms KPI KHKD.Watch the agent work
While the agent runs,build prints what it does on stderr, one line per step, with the seconds since the start. Before the agent starts, it prints the work folder and what each file in it is for.
The raw events are always kept in
harness.jsonl in the work folder.
Configure it
The builder reads aglossary_builder: section of your ladygraph.yaml.
A key never goes in the config.
api_key_env names the environment variable that holds it. Leave the setting out if your endpoint does not check keys.The gateway
The model endpoint is yours to run, outside ladyGraph. ladyGraph ships no gateway, starts none, and depends on no gateway library. The endpoint must provide:- The Anthropic Messages API at
<base_url>/v1/messages, including tool use. Claude Code sends its requests in this format. A gateway that translates to another provider, such as LiteLLM, is fine if the model behind it can call tools. - A model list at
<base_url>/v1/modelsin OpenAI style. Onlydoctoruses it, to check thatengineis served.
The agent fails on its second turn with a 500 error
The agent fails on its second turn with a 500 error
Claude Code resends the model’s earlier thinking on every turn after a tool call. With LiteLLM in front of the
nvidia_nim models, a request whose history holds a thinking block returned 500 'NoneType' object has no attribute 'choices'. The same request without the block worked.The fix was a small LiteLLM callback that removes thinking blocks from the request history. The tutorial ships it as strip_thinking.py in ladygraph/tutorial/07_translation/liteLLMExample/. Restart the proxy after changing its config. Other gateways and models may behave differently.Use the term list in translation
Two hooks connect a glossary to the translate-then-tag extractor (translate_ner). The code does not connect them for you.
hintspasses the glossary terms found in each passage into the translation prompt.term_hint(text, glossary)builds the note, and it includes both proposed and approved terms.checkadds the gate.make_check(glossary)flags a translation that drops an approved term, and the line is then escalated to the stronger model.