# debug_fragment_validator URL: /chirp/api/middleware/debug_fragment_validator/ Section: middleware -------------------------------------------------------------------------------- debug_fragment_validator - Chirp window.BENGAL_THEME_DEFAULTS = { appearance: 'light', palette: 'charcoal-bengal' }; window.Bengal = window.Bengal || {}; window.Bengal.enhanceBaseUrl = '/chirp/assets/js/enhancements'; window.Bengal.watchDom = true; window.Bengal.debug = false; window.Bengal.enhanceUrls = { 'toc': '/chirp/assets/js/enhancements/toc.736b857e.js', 'docs-nav': '/chirp/assets/js/enhancements/docs-nav.57e4b129.js', 'tabs': '/chirp/assets/js/enhancements/tabs.aac9e817.js', 'lightbox': '/chirp/assets/js/enhancements/lightbox.1ca22aa1.js', 'interactive': '/chirp/assets/js/enhancements/interactive.96c8880c.js', 'mobile-nav': '/chirp/assets/js/enhancements/mobile-nav.d991657f.js', 'action-bar': '/chirp/assets/js/enhancements/action-bar.d62417f4.js', 'copy-link': '/chirp/assets/js/enhancements/copy-link.7d9a5c29.js', 'data-table': '/chirp/assets/js/enhancements/data-table.1f5bc1eb.js', 'lazy-loaders': '/chirp/assets/js/enhancements/lazy-loaders.a5c38245.js', 'holo': '/chirp/assets/js/enhancements/holo.ee13c841.js', 'link-previews': '/chirp/assets/js/enhancements/link-previews.96620bcf.js' }; (function () { try { var defaults = window.BENGAL_THEME_DEFAULTS || { appearance: 'system', palette: '' }; var defaultAppearance = defaults.appearance; if (defaultAppearance === 'system') { defaultAppearance = (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light'; } var storedTheme = localStorage.getItem('bengal-theme'); var storedPalette = localStorage.getItem('bengal-palette'); var theme = storedTheme ? (storedTheme === 'system' ? defaultAppearance : storedTheme) : defaultAppearance; var palette = storedPalette ?? defaults.palette; document.documentElement.setAttribute('data-theme', theme); if (palette) { document.documentElement.setAttribute('data-palette', palette); } } catch (e) { document.documentElement.setAttribute('data-theme', 'light'); } })(); Skip to main content For a complete page index, fetch /chirp/llms.txt. ⌁⌁ DocumentationInfoAboutGet StartedBuild AppsQuality and OperationsFile TextReferenceCubeExamplesApplied TutorialsReleasesDevGitHubChirp API ReferenceForum Magnifying Glass Search ⌘K Palette Appearance Chevron Down Mode Monitor System Sun Light Moon Dark Palette Snow Lynx Brown Bengal Silver Bengal Charcoal Bengal Blue Bengal List Chirp API Reference Caret Right Internal asgi invoke invoke_plan kwargs_resolve multimap types Caret Right Ai _providers _structured errors llm streaming Caret Right App compiler diagnostics lifecycle mount registry runtime server state url_for Caret Right Cache Caret Right Backends memory null redis deferred key middleware protocol Caret Right Cli Caret Right Templates minimal scaffold shell sse v2 _check _freeze _makemigrations _new _resolve _routes _run _security_check _templates Caret Right Contracts checker declarations patterns routes rules_accessibility rules_alpine_cdn rules_boundary rules_chirpui_runtime rules_commands rules_composition rules_context_cascade rules_csrf_forms rules_debug_wiring rules_defer_falsy rules_form_routes rules_forms rules_fragment_scope rules_fragment_targets rules_htmx rules_inline rules_islands rules_kida_analysis rules_layout rules_live_blocks rules_mount_app rules_oob_registry rules_oob_targets rules_page_handlers rules_page_shell rules_reactive rules_route_contract rules_route_names rules_safety rules_sse rules_swap rules_unreachable_blocks rules_vary template_scan types utils Caret Right Data Caret Right Drivers postgres sqlite Caret Right Schema diff generate introspect operations parse types _mapping _sqlite database errors migrate pagination query types Caret Right Docs autodoc checks collection frontmatter models plugin search tools Caret Right Ext chirp_ui Caret Right Http cookies forms headers query request response sync_request Caret Right I18N catalog detection formatting middleware Caret Right Markdown errors filters renderer Caret Right Middleware _redis_rate_limit allowed_hosts auth auth_rate_limit builtin csp_nonce csrf debug_fragment_validator inject layout_debug protocol security_headers sessions static streaming_html Caret Right Pages actions context debug discovery Caret Right index bus events stream renderer resolve sections shell_actions shell_context types Caret Right Realtime events sse Caret Right Routing params route router Caret Right Security audit decorators lockout passwords urls Caret Right Server Caret Right Debug editor frames render_plan_snapshot renderers request_context styles template_context alpine debug_page debug_runtime delegation dev dev_browser_reload devtools errors fragment_dispatch fragment_targets_debug handler handler_kwargs htmx_debug htmx_safe_target islands negotiation negotiation_oob production route_explorer sender speculation_rules sse_lifecycle sync_handler terminal_checks terminal_errors view_transitions Caret Right Templating adapter composition filters fragment_target_registry integration kida_adapter macros navigation_swap oob_registry render_plan returns streaming suspense trace Caret Right Testing assertions client route_smoke sse Caret Right Tools events handler registry schema Caret Right Validation result rules chirp config context domains errors extraction freeze health live_blocks logging plugin resilience shell_actions shell_regions sources Chirp API ReferenceMiddleware ᗢ Caret Down Link Copy URL External Open LLM text Copy Copy LLM text Share with AI Ask Claude Ask ChatGPT Ask Gemini Ask Copilot Module middleware.debug_fragment_validator Debug-mode validator for fragment responses. Catches silent failure modes where a fragment response would paint a broken page in the browser: <!DOCTYPE in fragment body (a full page rendered into an outlet). Duplicate id="..." for registered shell-region ids (would collide with the live DOM after the swap). Only active when AppConfig.debug=True; auto-registered during _collect_builtin_middleware when an OOB registry is present. Warns by default; strict=True raises instead for CI enforcement. 2Classes2Functions Classes FragmentValidationError 0 ▼ Raised by ``DebugFragmentValidator`` in strict mode when a fragment response leaks full-page markup… Raised by DebugFragmentValidator in strict mode when a fragment response leaks full-page markup or duplicate ids. DebugFragmentValidator 2 ▼ Middleware that inspects fragment responses for breakage patterns. Only inspects buffered ``Respon… Middleware that inspects fragment responses for breakage patterns. Only inspects buffered Response objects with text/html content when render_intent == "fragment" (or "unknown" on an htmx request, matching HTMLInject's skip rule). Streaming responses are skipped — buffering them would defeat the point of streaming and the body is rarely available as a single string anyway. Methods Internal Methods 2 ▼ __init__ 2 ▼ def __init__(self, oob_registry: OOBRegistry, *, strict: bool = False) -> None Parameters Name Type Description oob_registry — strict — Default: False __call__ 2 AnyResponse ▼ async async def __call__(self, request: Request, next: Next) -> AnyResponse Parameters Name Type Description request — next — Returns AnyResponse Functions _count_id_occurrences 2 int ▼ Count ``id="target_id"`` and ``id='target_id'`` occurrences. def _count_id_occurrences(body: str, target_id: str) -> int Parameters Name Type Description body str target_id str Returns int _is_selectable_shell_outlet_response 2 bool ▼ True for app-shell boosted responses meant to be narrowed by hx-select. The br… def _is_selectable_shell_outlet_response(body: str, request: Request) -> bool True for app-shell boosted responses meant to be narrowed by hx-select. The browser owns the inherited hx-select="#page-content" attribute; it is not sent as a request header. In debug mode this validator sees the pre-selection response, so a correctly selectable shell-outlet response can look like a full document with duplicate shell-region ids. Treat the canonical app-shell shape as valid when the response contains the selector target htmx will extract. Parameters Name Type Description body str request Request Returns bool ← Previous csrf Next → inject List Magnifying Glass ESC Recent Clear Magnifying Glass No results for "" Start typing to search... ↑↓ Navigate ↵ Open ESC Close Powered by Lunr ⌁⌁ Magnifying Glass Search X Close Documentation Caret Down Info About Get Started Build Apps Quality and Operations File Text Reference Cube Examples Applied Tutorials Releases Dev Caret Down GitHub Chirp API Reference Forum Palette Appearance Chevron Down Mode Monitor System Sun Light Moon Dark Palette Snow Lynx Brown Bengal Silver Bengal Charcoal Bengal Blue Bengal © 2026 Chirp built in ᓚᘏᗢ { "linkPreviews": { "enabled": true, "hoverDelay": 200, "hideDelay": 150, "showSection": true, "showReadingTime": true, "showWordCount": true, "showDate": true, "showTags": true, "maxTags": 3, "includeSelectors": [".prose"], "excludeSelectors": ["nav", ".toc", ".breadcrumb", ".pagination", ".card", "[class*='-card']", ".tab-nav", "[class*='-widget']", ".child-items", ".content-tiles"], "allowedHosts": [], "allowedSchemes": ["https"], "hostFailureThreshold": 3, "showDeadLinks": true } } window.BENGAL_LAZY_ASSETS = { tabulator: '/chirp/assets/js/tabulator.min.js', dataTable: '/chirp/assets/js/data-table.js', mermaidToolbar: '/chirp/assets/js/mermaid-toolbar.9de5abba.js', mermaidTheme: '/chirp/assets/js/mermaid-theme.344822c5.js', graphMinimap: '/chirp/assets/js/graph-minimap.ff04e939.js', graphContextual: '/chirp/assets/js/graph-contextual.355458ba.js' }; window.BENGAL_ICONS = { close: '/chirp/assets/icons/close.911d4fe1.svg', enlarge: '/chirp/assets/icons/enlarge.652035e5.svg', copy: '/chirp/assets/icons/copy.3d56e945.svg', 'download-svg': '/chirp/assets/icons/download.04f07e1b.svg', 'download-png': '/chirp/assets/icons/image.c34dfd40.svg', 'zoom-in': '/chirp/assets/icons/zoom-in.237b4a83.svg', 'zoom-out': '/chirp/assets/icons/zoom-out.38857c77.svg', reset: '/chirp/assets/icons/reset.d26dba29.svg' }; { "prerender": [ { "where": { "and": [ { "href_matches": "/docs/*" }, { "not": { "selector_matches": "[data-external], [target=_blank], .external" } } ] }, "eagerness": "conservative" } ], "prefetch": [ { "where": { "and": [ { "href_matches": "/*" }, { "not": { "selector_matches": "[data-external], [target=_blank], .external" } } ] }, "eagerness": "conservative" } ] } Arrow Up -------------------------------------------------------------------------------- Metadata: - Word Count: 1111 - Reading Time: 6 minutes