Skip to content

fix(docs-gen): fence bare docstring examples and escape MDX braces (SAO-18112) - #320

Merged
etserend merged 4 commits into
mainfrom
fix/sao-18112-fence-bare-examples
Nov 24, 2026
Merged

etserend merged 4 commits into
mainfrom
fix/sao-18112-fence-bare-examples

Conversation

@etserend

@etserend etserend commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes SAO-18112. The reference-docs generator (scripts/create_docs.py) only fenced >>> doctest examples. Bare examples in SDK docstrings were emitted as brace-escaped prose, so code rendered as plain text, # comments became headings, and braces showed as \{...\} on every regeneration (for example the dataset reference page).

Changes

  • Add _render_examples / _strip_doctest_prompts: every example is fenced as ```python, doctest prompts are stripped on every line (not just the first), and examples that already contain a fence pass through unchanged. Replaces the duplicated loops in write_function and write_class.
  • Examples with an RST :: lead-in go through _sanitize_description, so only the indented code is fenced and the prose stays prose (found in Astra review: get_metric_aggregate).
  • Notes use _sanitize_description, so :: blocks in notes are fenced and their braces are not escaped.
  • Examples that are plain Markdown bullet lists (e.g. generate_unique_name in utils/prompts.py) stay prose through _sanitize_description instead of being fenced as Python (found in the second Astra round). YAML-style - key: value lists stay fenced as code.
  • RST :: examples strip >>> / ... prompts before conversion (second Astra round). _strip_doctest_prompts keeps indentation and leaves an indented bare ... placeholder body alone.
  • Simplify the NotFoundError docstring examples in src/splunk_ao/exceptions.py; the non-raw \\" escapes rendered as invalid Python (b"{\\"detail\\": ...}"). Docstring-only change, same example meaning.
  • Render module-level examples in write_module (previously dropped; no visible effect today because __init__ modules are not emitted).
  • Skip inline code spans of any backtick width when escaping braces, so RST ``literals`` no longer show literal backslashes.

Validation

Generated reference docs from this branch (rebased on origin/main) vs the docs repo main, 81 pages each:

Before After
Escaped-brace occurrences 86 4 (bare prose braces, intended)
Examples sections with no fence at all 105 of 122 1 of 122 (the intentional bullet list in utils/prompts)
Fenced Examples blocks that do not parse as Python 2 0
Files removed or added n/a 0
Sections removed or added n/a 0
Pages that fail MDX compile (@mdx-js/mdx) 0 0
  • Publish Docs was dispatched from this branch and opened agent-observability-docs#173. All 6 of its checks pass, including the Mintlify deployment and dev-server checks. The Mintlify preview was checked for dataset (examples are code blocks, braces literal) and experiment / get_metric_aggregate (prose outside the fence, no stray ::).
  • pytest tests/test_create_docs_helpers.py -n 0: 45 passed (23 new).
  • ruff check --no-fix scripts tests/test_create_docs_helpers.py: 2 findings (RET504 in _sanitize_description, I001 in the test file), both present on main and left untouched.

Rendered result (Mintlify preview of agent-observability-docs#173)

Preview: https://agent-observability-docs-feat-update-docs-fix-sao-18112-fen.mintlify.site/sdk-api/python/reference/dataset

Confirmed by eye on the dataset page in a browser (not only by script):

  • The Examples section renders as a single highlighted Python code block with the site's copy button. Before this change the same section rendered as a paragraph, and each # comment line became a large heading.
  • Braces are literal: {"input": "What is machine learning?", "output": "Machine learning ..."}, with no \{ / \} backslashes.
  • The page's "On this page" table of contents lists the methods (add_rows, create, delete, extend, generate, get, get_content, get_version_content, get_versions, list, refresh, save), so no sections were lost.
  • experiment > get_metric_aggregate: the sentence "Poll until a specific metric is computed, then assert" is plain text above the code block, the stray :: is gone, and the code is a normal block.

Known limitations (not in this PR)

  • publish-docs.yaml installs docstring-parser>=0.17.0 unpinned, so CI output can differ from a local run for reasons unrelated to this change (for example count (int, default 10) vs count (int) on datasets). Pinning it is a separate follow-up.

  • Code produced from an RST :: block starts with one blank line inside the fence. This comes from the existing _convert_rst_code_blocks and is locked in by existing tests.

  • Doctest output lines can land inside python fences (for example UnconfiguredProvider in provider.py). The extraction logic is unchanged; worth a separate ticket.

  • Optional CI hardening in publish-docs.yaml (run the helper tests, pin docstring-parser) is a follow-up.

etserend added a commit that referenced this pull request Nov 23, 2026
…s code (SAO-18112)

Address Astra review on #320:
- Examples with an RST `::` lead-in are routed through _sanitize_description
  so only the indented code is fenced; the prose and `::` marker are no
  longer swallowed into a python block (e.g. get_metric_aggregate).
- Notes use _sanitize_description so `::` blocks in notes are fenced and
  their braces are not escaped.
- Add regression tests for both shapes.

Co-Authored-By: Claude <noreply@anthropic.com>
etserend and others added 2 commits November 23, 2026 16:51
…AO-18112)

The generator only fenced >>> doctest examples, so bare examples in SDK
docstrings were emitted as brace-escaped prose on every regeneration.

- Add _render_examples/_strip_doctest_prompts: every example is fenced as
  python, doctest prompts are stripped per line, pre-fenced examples pass
  through. Replaces the duplicated loops in write_function and write_class.
- Render module-level examples in write_module (previously dropped).
- Escape braces in notes so they cannot break MDX.
- Skip inline code spans of any backtick width when escaping braces, so
  RST ``literals`` no longer show literal backslashes.
- Add regression tests for bare, doctest, mixed and pre-fenced examples,
  multi-backtick spans, and module examples.

Co-Authored-By: Claude <noreply@anthropic.com>
…s code (SAO-18112)

Address Astra review on #320:
- Examples with an RST `::` lead-in are routed through _sanitize_description
  so only the indented code is fenced; the prose and `::` marker are no
  longer swallowed into a python block (e.g. get_metric_aggregate).
- Notes use _sanitize_description so `::` blocks in notes are fenced and
  their braces are not escaped.
- Add regression tests for both shapes.

Co-Authored-By: Claude <noreply@anthropic.com>
@etserend
etserend force-pushed the fix/sao-18112-fence-bare-examples branch from 8495fac to af76190 Compare November 23, 2026 22:52
Examples that are plain Markdown bullet lists (for example
generate_unique_name in utils/prompts.py) were fenced as python after the
fence-everything change. Render bullet-only examples as prose through
_sanitize_description so braces are still escaped. YAML-style `- key: value`
lists stay fenced as code.

Co-Authored-By: Claude <noreply@anthropic.com>

@etserend etserend left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 This review was generated by the Astra agent (claude-opus-5-5). It may contain mistakes.

Verdict: approve — Examples and notes now render correctly. Regenerated docs differ from main only in the intended fences and brace escapes. The earlier :: concern is fixed.

Addressed before this review

  • RST :: lead-in examples (for example get_metric_aggregate) were fenced as Python together with their prose and the :: marker. Fixed in af76190: these examples now go through _sanitize_description, and TestRstLiteralBlockExamples covers them.

Follow-ups

Suggested follow-up work that could be tracked as Jira tickets:

  • scripts/create_docs.py:606-608: The :: branch sends the example through _sanitize_description, and that path never calls _strip_doctest_prompts. An RST literal block that holds >>> lines would keep its prompts inside the fence. No docstring in src/splunk_ao has this shape today. I searched for :: lines followed by >>> within 3 lines and found none. Consider stripping the prompts inside the converted block, and add a test for it.
  • src/splunk_ao/exceptions.py:101-102: This docstring is not raw, so \\" becomes \" in the rendered example. The result is b"{\\"detail\\": ...}", which is not valid Python. It is the only fenced example in the regenerated docs that ast.parse rejects. Make the docstring raw, or simplify the literal.

…le (SAO-18112)

Address the second Astra round on #320:
- RST `::` examples now strip doctest prompts before conversion;
  _strip_doctest_prompts keeps indentation and leaves an indented bare
  `...` placeholder body untouched.
- Simplify the NotFoundError docstring examples so the rendered code is
  valid Python (the non-raw `\\"` escapes rendered as `\\\\"`).

Co-Authored-By: Claude <noreply@anthropic.com>
@etserend

Copy link
Copy Markdown
Contributor Author

🤖 This review was generated by the Astra agent (claude-opus-5-5). It may contain mistakes.

Verdict: approve — Examples and notes now render correctly. Regenerated docs differ from main only in the intended fences and brace escapes. The earlier :: concern is fixed.

Addressed before this review

  • RST :: lead-in examples (for example get_metric_aggregate) were fenced as Python together with their prose and the :: marker. Fixed in af76190: these examples now go through _sanitize_description, and TestRstLiteralBlockExamples covers them.

Follow-ups

Suggested follow-up work that could be tracked as Jira tickets:

  • scripts/create_docs.py:606-608: The :: branch sends the example through _sanitize_description, and that path never calls _strip_doctest_prompts. An RST literal block that holds >>> lines would keep its prompts inside the fence. No docstring in src/splunk_ao has this shape today. I searched for :: lines followed by >>> within 3 lines and found none. Consider stripping the prompts inside the converted block, and add a test for it.
  • src/splunk_ao/exceptions.py:101-102: This docstring is not raw, so \\" becomes \" in the rendered example. The result is b"{\\"detail\\": ...}", which is not valid Python. It is the only fenced example in the regenerated docs that ast.parse rejects. Make the docstring raw, or simplify the literal.

Both fixed in aeb14f2 (:: blocks now strip >>> prompts, and the NotFoundError examples are valid Python).

@etserend
etserend merged commit c48dc1b into main Nov 24, 2026
14 checks passed
@etserend
etserend deleted the fix/sao-18112-fence-bare-examples branch November 24, 2026 01:36
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants