Turkish Prompt Compiler
Optimize for downstream token efficiency and execution reliability. Do not treat English translation, Markdown, XML, or brevity as goals by themselves.
Apply the correct boundary
- Recognize that the current user message has already consumed input tokens. Never claim that rewriting it reduces the current call's input usage.
- Optimize only text that will be reused, forwarded, stored as a prompt, or explicitly analyzed.
- Include the optimizer's own billable call when estimating net savings.
- Treat token counts as model- and encoding-specific. Never present character counts or estimates as exact token counts.
- Preserve the user's requested response language independently from the prompt's internal language.
Run the workflow
- Identify the target model or encoding, reuse count, destination, required output language, and whether the prompt is one-shot or staged.
- Extract a semantic contract:
- primary task;
- required coverage;
- constraints and exclusions;
- deliverables;
- named entities and terminology;
- output language, format, depth, and audience.
- Protect content that must remain exact:
- code, SQL, commands, logs, URLs, file paths, JSON/XML, identifiers;
- names, dates, numbers, units, thresholds, quotations, citations;
- negations and scope terms such as
değil, hariç, yalnızca, en az, and en fazla;
- domain terms whose Turkish spelling carries meaning.
- Select a structure using structure-selection.md.
- Generate only relevant candidates:
- compact Turkish;
- compact English control language with Turkish proper nouns and domain terms preserved;
- shallow XML only for staged execution, scope boundaries, or machine-controlled workflows.
- Measure the original and candidates with the target model's tokenizer. Use
scripts/count_tokens.cjs when tiktoken is available.
- Reject any candidate that changes the semantic contract, even when it is shorter.
- Prefer the shortest surviving candidate only when the reduction is meaningful:
- below 10%: retain the clearer version;
- 10–20%: optimize only if fidelity is unambiguous;
- above 20%: use the shorter candidate after validation.
- Report input savings separately from expected output usage. Flag prompts whose requested output dominates total cost.
Choose the prompt language
- Keep short prompts in Turkish; translation overhead and review risk usually outweigh savings.
- For long downstream prompts, compare compact Turkish against compact English rather than assuming English is cheaper.
- Preserve Turkish names and specialist terms when translation could alter retrieval, citation, legal meaning, or historical identity.
- Add one concise instruction such as
Answer in Turkish when using English control language.
- Avoid word-by-word Turkish-English replacement. Rewrite the whole instruction coherently.
Use XML selectively
- Use shallow XML when the workflow has an active stage, explicit inclusions/exclusions, reusable project context, or automated parsing.
- Keep the hierarchy flat. Prefer a few meaningful tags such as
<task>, <coverage>, <active_stage>, <deliver>, <exclude>, and <rule>.
- Do not wrap every bullet or sentence in a tag.
- Do not use XML for a simple one-shot request solely because it is long.
- Compare equivalent plain and XML candidates. Attribute savings from reduced scope separately from XML tag overhead.
- For staged work, keep stable project context reusable and change only
<active_stage>.
Validate fidelity
Before selecting a candidate, verify all of the following:
- Every required topic appears.
- Every deliverable appears.
- Numbers, names, technologies, sources, regions, and alternatives remain intact.
- Optional preferences have not become requirements, or vice versa.
- No negation, exception, or scope boundary changed.
- The response language and audience remain explicit.
- Compression has not introduced ambiguous shorthand.
If any check fails, repair the candidate and recount it. If exact tokenizer access is unavailable, label counts as estimates or omit them; never fabricate precision.
Calculate savings
Use:
input_saving_rate = 1 - optimized_tokens / original_tokens
For repeated downstream use:
net_tokens_saved =
reuse_count * (original_tokens - optimized_tokens)
- optimizer_billable_tokens
Do not claim total-call savings without considering output tokens:
total_saving_rate =
(original_input - optimized_input)
/ (original_input + expected_output)
Present results
When the user asks for analysis, return:
- A table containing original and candidate token counts by encoding.
- Savings percentages.
- The recommended optimized prompt.
- A brief fidelity note.
- A warning when output scope is the larger cost driver.
When the user asks only for an optimized prompt, return the optimized prompt without exposing intermediate candidates unless needed.
When optimizing silently for a downstream call, forward only the selected candidate and retain the semantic contract for validation.
Token counter
Run:
node scripts/count_tokens.cjs --encoding o200k_base --file prompt.txt
node scripts/count_tokens.cjs --model <target-model> --file original.txt --file optimized.txt
The script emits JSON with character and token counts. If the installed tiktoken package does not recognize a model, use the explicitly verified encoding instead of guessing.
1---2name: turkish-prompt-compiler3description: Analyze, measure, and optimize substantial Turkish prompts without losing intent, constraints, terminology, or protected content. Use when the user explicitly asks for Turkish prompt token analysis, compression, translation, restructuring, or optimization, or when a long Turkish instruction will be forwarded to another model, API, agent, or repeated workflow. Do not use for ordinary Turkish conversation, short requests handled directly, or verbatim editing unless optimization is explicitly requested.4---56# Turkish Prompt Compiler78Optimize for downstream token efficiency and execution reliability. Do not treat English translation, Markdown, XML, or brevity as goals by themselves.910## Apply the correct boundary1112- Recognize that the current user message has already consumed input tokens. Never claim that rewriting it reduces the current call's input usage.13- Optimize only text that will be reused, forwarded, stored as a prompt, or explicitly analyzed.14- Include the optimizer's own billable call when estimating net savings.15- Treat token counts as model- and encoding-specific. Never present character counts or estimates as exact token counts.16- Preserve the user's requested response language independently from the prompt's internal language.1718## Run the workflow19201. Identify the target model or encoding, reuse count, destination, required output language, and whether the prompt is one-shot or staged.212. Extract a semantic contract:22 - primary task;23 - required coverage;24 - constraints and exclusions;25 - deliverables;26 - named entities and terminology;27 - output language, format, depth, and audience.283. Protect content that must remain exact:29 - code, SQL, commands, logs, URLs, file paths, JSON/XML, identifiers;30 - names, dates, numbers, units, thresholds, quotations, citations;31 - negations and scope terms such as `değil`, `hariç`, `yalnızca`, `en az`, and `en fazla`;32 - domain terms whose Turkish spelling carries meaning.334. Select a structure using [structure-selection.md](references/structure-selection.md).345. Generate only relevant candidates:35 - compact Turkish;36 - compact English control language with Turkish proper nouns and domain terms preserved;37 - shallow XML only for staged execution, scope boundaries, or machine-controlled workflows.386. Measure the original and candidates with the target model's tokenizer. Use `scripts/count_tokens.cjs` when `tiktoken` is available.397. Reject any candidate that changes the semantic contract, even when it is shorter.408. Prefer the shortest surviving candidate only when the reduction is meaningful:41 - below 10%: retain the clearer version;42 - 10–20%: optimize only if fidelity is unambiguous;43 - above 20%: use the shorter candidate after validation.449. Report input savings separately from expected output usage. Flag prompts whose requested output dominates total cost.4546## Choose the prompt language4748- Keep short prompts in Turkish; translation overhead and review risk usually outweigh savings.49- For long downstream prompts, compare compact Turkish against compact English rather than assuming English is cheaper.50- Preserve Turkish names and specialist terms when translation could alter retrieval, citation, legal meaning, or historical identity.51- Add one concise instruction such as `Answer in Turkish` when using English control language.52- Avoid word-by-word Turkish-English replacement. Rewrite the whole instruction coherently.5354## Use XML selectively5556- Use shallow XML when the workflow has an active stage, explicit inclusions/exclusions, reusable project context, or automated parsing.57- Keep the hierarchy flat. Prefer a few meaningful tags such as `<task>`, `<coverage>`, `<active_stage>`, `<deliver>`, `<exclude>`, and `<rule>`.58- Do not wrap every bullet or sentence in a tag.59- Do not use XML for a simple one-shot request solely because it is long.60- Compare equivalent plain and XML candidates. Attribute savings from reduced scope separately from XML tag overhead.61- For staged work, keep stable project context reusable and change only `<active_stage>`.6263## Validate fidelity6465Before selecting a candidate, verify all of the following:6667- Every required topic appears.68- Every deliverable appears.69- Numbers, names, technologies, sources, regions, and alternatives remain intact.70- Optional preferences have not become requirements, or vice versa.71- No negation, exception, or scope boundary changed.72- The response language and audience remain explicit.73- Compression has not introduced ambiguous shorthand.7475If any check fails, repair the candidate and recount it. If exact tokenizer access is unavailable, label counts as estimates or omit them; never fabricate precision.7677## Calculate savings7879Use:8081```text82input_saving_rate = 1 - optimized_tokens / original_tokens83```8485For repeated downstream use:8687```text88net_tokens_saved =89 reuse_count * (original_tokens - optimized_tokens)90 - optimizer_billable_tokens91```9293Do not claim total-call savings without considering output tokens:9495```text96total_saving_rate =97 (original_input - optimized_input)98 / (original_input + expected_output)99```100101## Present results102103When the user asks for analysis, return:1041051. A table containing original and candidate token counts by encoding.1062. Savings percentages.1073. The recommended optimized prompt.1084. A brief fidelity note.1095. A warning when output scope is the larger cost driver.110111When the user asks only for an optimized prompt, return the optimized prompt without exposing intermediate candidates unless needed.112113When optimizing silently for a downstream call, forward only the selected candidate and retain the semantic contract for validation.114115## Token counter116117Run:118119```bash120node scripts/count_tokens.cjs --encoding o200k_base --file prompt.txt121node scripts/count_tokens.cjs --model <target-model> --file original.txt --file optimized.txt122```123124The script emits JSON with character and token counts. If the installed `tiktoken` package does not recognize a model, use the explicitly verified encoding instead of guessing.