feat(translation): prepare requests for routed targets - #455
Draft
afourniernv wants to merge 1 commit into
Draft
Conversation
Signed-off-by: Alex Fournier <afournier@nvidia.com>
This was referenced Aug 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds one translation-layer operation that selects a routed target and optionally prepends that target's system prompt without dropping provider-specific request fields.
This is 1 of 3 for SWITCH-1253. It establishes the wire-format boundary only; it does not add target configuration or change router behavior by itself.
Before
Routing hosts changed the normalized request when selecting a candidate:
The normalized request can also retain an exact provider body so same-format forwarding preserves fields Switchyard does not model. Changing only the normalized request could leave that exact body with the route alias and no target prompt. Dropping the exact body avoided stale replay, but also dropped provider-specific fields.
After
Target selection and prompt insertion are one provider-aware operation:
The helper updates the normalized request and exact preserved OpenAI Chat, OpenAI Responses, and Anthropic Messages bodies together. Existing system content and provider-only fields remain intact, while a same-format encode cannot restore the route alias or omit the target prompt.
For a custom exact format, an unprompted request remains untouched. If a configured prompt cannot be patched safely, the stale exact replay is discarded rather than silently forwarding a request without the prompt.
Why this layer owns the operation
Libsy decides which target prompt applies; the translation layer knows how each provider represents model and system content. Keeping provider mutation here prevents libsy, the native server, and custom hosts from implementing separate OpenAI and Anthropic patching rules.
Scope and compatibility
prepare_request_for_target(...)as an exported translation helper.Validation
cargo test -p switchyard-translationcargo clippy -p switchyard-translation --all-targets -- -D warningscargo fmt --all -- --checkSuggested review order
crates/switchyard-translation/src/util.rs— helper contract and exact-body patching rulescrates/switchyard-translation/tests/request_translation.rs— provider preservation and failure boundariescrates/switchyard-translation/src/lib.rs— public exportStack
targets.*.system_prompt, compatibility, docs, and integration testsThe later two PRs are drafts and currently show cumulative diffs against
main. Their descriptions identify the commit and line count unique to each layer; those diffs will shrink as the parent PRs merge.