Skip to content

Improve code example visibility: Show relevant code first, not boilerplate imports #253

@neubig

Description

@neubig

Description

When viewing code examples in the SDK documentation, the expandable code sections show import statements and boilerplate (LLM setup, etc.) in the visible portion, while the actual relevant code for the topic is hidden until the user expands the section.

This creates a suboptimal reading experience where users must always expand code sections to find the code they should focus on.

Example

From the Conversation Persistence guide:

  • The code block has 102 lines
  • Only import statements are visible before expansion
  • The relevant code demonstrating conversation persistence is hidden

This pattern appears across many documentation pages.

Suggested Improvement

Consider restructuring code examples so that:

  1. The relevant/topic-specific code is visible first (before expansion)
  2. Boilerplate imports and setup code are secondary (visible after expansion, or at the bottom)

Possible approaches:

  • Reorder code blocks to put the most relevant code at the top
  • Use separate code blocks: one for the key concept (visible) and one for full runnable example (expandable)
  • Add line highlighting to draw attention to the relevant portions
  • Consider a "focus mode" that shows only the relevant lines initially

Impact

This would improve the reader experience by making the documentation more scannable and reducing the friction to understand each concept.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions