Render the structured-output schema in commons, not per-SDK wrappers

Author: sanchitmonga22Created Sep 11, 2026Updated Sep 11, 2026
Labelstech-debtcore

Follow-up from #840 by @ayaangazali -- thanks again for that PR!

What

idl/structured_output.proto:42-44 documents that include_schema_in_prompt should "render the schema into the system prompt," but commons only honors that for validation: core/src/features/llm/llm_module.cpp:2443-2445 reads the flag into structured_config, used post-generation by set_structured_output_if_present; options_from_request (llm_module.cpp:1637-1667) only compiles the schema to GBNF grammar and passes through the request's own system_prompt unchanged. The only code that actually renders the schema into the prompt lives in the Swift, Web, and now Flutter wrapper facades that call preparePrompt by hand.

Why it matters

Canonical llm.generateStructured in Swift, Kotlin and React Native sets includeSchemaInPrompt but never calls preparePrompt, so those paths still never show the schema to the model -- the documented proto behavior isn't honored end to end, only in the SDKs that happen to duplicate the wrapper pattern. The repo's own architecture guidance is to put logic at the lowest layer that serves everyone.

Suggested approach

Move schema-into-system-prompt rendering into rac_llm_generate_proto itself (gated on include_schema_in_prompt, honoring its documented default when unset), then remove the per-SDK preparePrompt calls from the wrapper facades once commons does it uniformly.

Done when

  • Setting includeSchemaInPrompt on any SDK's canonical llm.generateStructured (Swift, Kotlin, React Native) results in the schema appearing in the system prompt sent to the model, without a wrapper-level preparePrompt call.
  • The wrapper-level preparePrompt special-casing can be simplified or removed without behavior loss.

Not blocking #840. @ayaangazali, you know this code well now -- you're welcome to take this one if you're interested.

Opened with help from Claude Code and Codex.

Reviewed with help from Claude Code and Codex.

Source: RunanywhereAI/runanywhere-sdks