refactor response validation - #55
Conversation
| Google, | ||
| Vertex, | ||
| Anthropic, | ||
| GoogleAdk, |
There was a problem hiding this comment.
🔴 Provider::GoogleAdk missing from MessageNum::matches_provider and convert_message_to_provider_type causes UnsupportedProviderError
Provider::GoogleAdk is added to the enum at crates/potato_type/src/lib.rs:69 but is not propagated to MessageNum::matches_provider (crates/potato_type/src/prompt/types.rs:284-293) or convert_message_to_provider_type (crates/potato_type/src/prompt/types.rs:338-349). When ChatResponse::to_message_num(&Provider::GoogleAdk) is called (crates/potato_provider/src/providers/types.rs:163-174), matches_provider returns false for a GeminiContentV1 message (which is the correct type for GoogleAdk), then convert_message_to_provider_type falls through to _ => Err(TypeError::UnsupportedProviderError). This makes it impossible to convert ADK response messages back into request messages for the GoogleAdk provider.
Prompt for agents
In crates/potato_type/src/prompt/types.rs, two functions need Provider::GoogleAdk support:
1. In matches_provider (line 284-293), add a new arm:
| (MessageNum::GeminiContentV1(_), Provider::GoogleAdk)
alongside the existing Gemini/Google/Vertex arms.
2. In convert_message_to_provider_type (line 338-349), add:
Provider::GoogleAdk => self.to_google_message(),
alongside the existing Google/Vertex/Gemini arms (before the _ wildcard).
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
this is fine for now. we mainly need it for request parsing
| Google, | ||
| Vertex, | ||
| Anthropic, | ||
| GoogleAdk, |
There was a problem hiding this comment.
🔴 Provider::GoogleAdk missing from GeminiGenerateContentRequest::match_provider causes request serialization failure
Provider::GoogleAdk is added to the enum at crates/potato_type/src/lib.rs:69 but is not propagated to GeminiGenerateContentRequest::match_provider at crates/potato_type/src/google/v1/generate/request.rs:2614-2619. When ProviderRequest::to_request(&Provider::GoogleAdk) is called (crates/potato_type/src/prompt/builder.rs:225-234), match_provider returns false and the method returns Err("ProviderRequest does not match the specified provider"). This prevents serializing any GoogleAdk prompt to its API request body.
Prompt for agents
In crates/potato_type/src/google/v1/generate/request.rs at line 2614-2619, update the match_provider function to include Provider::GoogleAdk:
fn match_provider(&self, provider: &Provider) -> bool {
matches!(
provider,
Provider::Gemini | Provider::Google | Provider::Vertex | Provider::GoogleAdk
)
}
Was this helpful? React with 👍 or 👎 to provide feedback.
Pull Request
Short Summary
Adds
Provider::GoogleAdkand refactorsChatResponse::from_response_valueto accept an optional provider hint, replacing a fragile key-only heuristic with a two-path design: direct deserialization when the provider is known, heuristic key inspection as a fallback. Fixes a bug where valid ADK responses without a"partial"key were misrouted or errored, and a second bug wherePrompt::new_rswithProvider::GoogleAdkand no explicit settings immediately returnedErr(InvalidModelSettings).Context
Root problem — ADK heuristic was too narrow. The old heuristic required
"partial"plus at least one other ADK field to route toAdkLlmV1. AllAdkLlmResponsefields are optional, so real ADK responses without"partial"misrouted toGeminiV1(if"candidates"was present) or fell through toErr. The fix introduces a provider-hint path that bypasses heuristics entirely when the caller knows the provider:Before:
After:
Heuristic improvements. The heuristic fallback now checks for any key in
ADK_SPECIFIC_KEYS(12 keys, includingusage_metadataandmodel_versionwhich ADK uses in snake_case vs Gemini's camelCaseusageMetadata/modelVersion). This check is ordered before the Gemini"candidates"check, preventing ADK responses that include"candidates"from silently producing emptyGeminiV1results.provider_default_settingsfix.Provider::GoogleAdkpreviously fell through toOpenAIChatSettings::default(), butvalidate_provider(GoogleAdk)requiresModelSettings::GoogleChat. Any ADK prompt created without explicit settings would immediately fail. NowGoogleAdk(alongsideGoogle,Vertex,Gemini) returnsModelSettings::GoogleChat(GeminiSettings::default()).crates/potato_type/src/lib.rsGoogleAdkvariant toProviderenum; adds#[cfg(test)]with round-trip tests for all 7 variantscrates/potato_type/src/prompt/settings.rsGoogleAdkarm tovalidate_provider; fixesprovider_default_settingsto returnGoogleChat; adds 4 testscrates/potato_type/src/prompt/interface.rsGoogleAdkto all Google provider groups (create_message_for_provider,get_system_role,settings_from_value,is_google_provider)crates/potato_provider/src/providers/types.rsfrom_response_valueinto provider-hinted + heuristic paths; expandsADK_SPECIFIC_KEYS; updates all 15 existing test calls; adds 13 new testspy-potato/python/potato_head/_potato_head.pyiGoogleAdk: "Provider"stub entryCargo.toml/Cargo.lock/py-potato/pyproject.toml/py-potato/uv.lockIs this a Breaking Change?
Yes —
ChatResponse::from_response_valuegains a required second argument (provider: Option<&Provider>). Any call site outside this crate must be updated to passNone(preserves existing heuristic behavior) or a specificProviderhint.