From dd63bcb05c0ad44276f67c9629d68dec29f71b19 Mon Sep 17 00:00:00 2001 From: Luis Novo Date: Sat, 11 Jul 2026 18:25:39 -0300 Subject: [PATCH] feat(prompts): steer models toward $$ math delimiters (#1057) Add a math formatting hint to the chat, source chat, Ask and transformation prompts: emit display math as $$...$$ and inline math as $...$ so formulas render via KaTeX, reserving fenced latex code blocks for when the user explicitly asks for the LaTeX source itself. Closes #1051 --- CHANGELOG.md | 3 +++ prompts/ask/final_answer.jinja | 4 ++++ prompts/chat/system.jinja | 4 ++++ prompts/source_chat/system.jinja | 4 ++++ prompts/transformation/execute.jinja | 4 ++++ 5 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f8b36c6b..d1fe2bcc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Release confidence process, documented and executable: `.github/RELEASE_PROCESS.md` now covers the risk-based test matrix (buckets A/B/C), the Docker image gate, the fix-loop re-test policy and the communication/credits/retro structure, backed by a new decision record (ADR-005) and versioned tooling under `scripts/release-test/` — `make release-test TAG= OLD_TAG=` runs fresh-install + upgrade scenarios against real images, and `make release-stack TAG= [DUMP=]` boots a browsable, isolated release-candidate stack (optionally with a copy of dev data) for manual verification +### Changed +- Chat, source chat, Ask and transformation prompts now steer models to write math as `$$...$$` (display) / `$...$` (inline) so formulas render via KaTeX, reserving fenced `latex` code blocks for when the user explicitly asks for the LaTeX source (#1051) + ### Removed - Dead Streamlit-era service layer (~2,000 lines): `api/client.py` (a synchronous HTTP client that called the app's own API) and 13 `api/*_service.py` wrappers that consumed the app's own HTTP API — none were imported by any router, command or test. Also removed the toy `process_text`/`analyze_data` demo commands (`commands/example_commands.py`) from the background worker - Pre-1.6 embedding job compatibility shims (the `embed_single_item`, `embed_chunk` and `vectorize_source` command handlers) — they existed only so jobs queued by a pre-1.6 version could drain after an upgrade, and any worker restarted on 1.6+ has no such jobs. **Upgrade note:** if you are upgrading from a version older than 1.6 with embedding jobs still queued, drain the queue on a 1.x release before upgrading past this change. Also removed dead tooling config from `pyproject.toml`: the `[tool.mypy]` block (the real config is `mypy.ini`) and Streamlit-era ruff per-file-ignores for files that no longer exist diff --git a/prompts/ask/final_answer.jinja b/prompts/ask/final_answer.jinja index 9c8b2d0f..ea65c951 100644 --- a/prompts/ask/final_answer.jinja +++ b/prompts/ask/final_answer.jinja @@ -26,6 +26,10 @@ Here are the answers you received for each of your queries. Based on the user question, the context and the retrieved answers, please formulate a final response to the user. +# MATH FORMATTING + +When showing math, write display math as $$...$$ and inline math as $...$ so formulas render properly. Only use fenced ```latex code blocks when the user explicitly asks for the LaTeX source itself. + # CITING SOURCES It's very important that your response contains references to the searched documents so the user can follow-up and read more about the topic. The way you do that is by adding the id of the specific document in between brackets like this: [document_id]. The references will be present on all the answers you have been provided. diff --git a/prompts/chat/system.jinja b/prompts/chat/system.jinja index f56e75be..bba67454 100644 --- a/prompts/chat/system.jinja +++ b/prompts/chat/system.jinja @@ -23,6 +23,10 @@ The user has selected this context to help you with your response: {{context}} {% endif %} +# MATH FORMATTING + +When showing math, write display math as $$...$$ and inline math as $...$ so formulas render properly. Only use fenced ```latex code blocks when the user explicitly asks for the LaTeX source itself. + # CITING INSTRUCTIONS If your answer is based off of any item in the context, it's very important that your response contains references to the searched documents so the user can follow-up and read more about the topic. The way you do that is by adding the id of the specific document in between brackets like this: [document_id]. diff --git a/prompts/source_chat/system.jinja b/prompts/source_chat/system.jinja index d7494061..de04e2df 100644 --- a/prompts/source_chat/system.jinja +++ b/prompts/source_chat/system.jinja @@ -27,6 +27,10 @@ When a user asks you a question, analyze both the source content and the availab {{ context }} {% endif %} +# MATH FORMATTING + +When showing math, write display math as $$...$$ and inline math as $...$ so formulas render properly. Only use fenced ```latex code blocks when the user explicitly asks for the LaTeX source itself. + # CITING INSTRUCTIONS When referencing information from the source or its insights, always include citations using the document IDs. This helps users track the specific content you're referencing. diff --git a/prompts/transformation/execute.jinja b/prompts/transformation/execute.jinja index a8310f54..4b18195e 100644 --- a/prompts/transformation/execute.jinja +++ b/prompts/transformation/execute.jinja @@ -1,3 +1,7 @@ {{ instructions }} +# MATH FORMATTING + +When showing math, write display math as $$...$$ and inline math as $...$ so formulas render properly. Only use fenced ```latex code blocks when the user explicitly asks for the LaTeX source itself. + # INPUT \ No newline at end of file