Skip to content

[firebase_vertexai]: VertexAISdkException: “Unhandled format for Content” when response is blocked by safety settings #17306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
1 task done
nrybarova opened this issue Apr 24, 2025 · 1 comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: all Issues / PRs which are for all platforms. plugin: vertexai label issues for vertexai plugin type: bug Something isn't working

Comments

@nrybarova
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Which plugins are affected?

No response

Which platforms are affected?

No response

Description

When using FirebaseVertexAI to generate content with safety settings enabled, if the model blocks the output for safety reasons (finishReason: SAFETY), the content field in the response is returned as an empty object ({}).

The SDK attempts to parse this content in parseContent(), but it doesn't match any of the expected structures. This results in an exception: Unhandled Exception: Unhandled format for Content: {}

Reproducing the issue

Steps to reproduce

  1. Use FirebaseVertexAI to call .generateContent() with strict SafetySettings (e.g. HarmBlockThreshold.low)
  2. Send a prompt that may trigger a moderation block (e.g. content related to harm/danger)
  3. Observe that the SDK throws VertexAISdkException: Unhandled format for Content

Firebase Core version

3.13.0

Flutter Version

3.27.1

Relevant Log Output

[ERROR:flutter/runtime/dart_vm_initializer.cc(40)] Unhandled Exception: Unhandled format for Content: {}
This indicates a problem with the Vertex AI in Firebase SDK. Try updating to the latest version (https://pub.dev/packages/firebase_vertexai/versions), or file an issue at https://github.com/firebase/flutterfire/issues.
#0      parseContent (package:firebase_vertexai/src/content.dart:79:10)
#1      _parseCandidate (package:firebase_vertexai/src/api.dart:904:11)
#2      MappedListIterable.elementAt (dart:_internal/iterable.dart:435:31)
#3      ListIterator.moveNext (dart:_internal/iterable.dart:364:26)
#4      new _GrowableList._ofEfficientLengthIterable (dart:core-patch/growable_array.dart:189:27)
#5      new _GrowableList.of (dart:core-patch/growable_array.dart:150:28)
#6      new List.of (dart:core-patch/array_patch.dart:39:18)
#7      ListIterable.toList (dart:_internal/iterable.dart:224:7)
#8      parseGenerateContentResponse (package:firebase_vertexai/src/api.dart:852:39)
<asynchronous suspens<>

Flutter dependencies

Expand Flutter dependencies snippet
- avatar_generator 0.0.5 [flutter]
- cached_network_image 3.4.1 [cached_network_image_platform_interface cached_network_image_web flutter flutter_cache_manager octo_image]
- client_kit 0.1.0 [master_kit rxdart collection meta email_validator get_it]
- collection 1.19.0
- cupertino_icons 1.0.8
- database_kit 0.1.0 [master_kit collection rxdart get_it json_annotation meta]
- device_info_plus 11.3.0 [device_info_plus_platform_interface ffi file flutter flutter_web_plugins meta web win32 win32_registry]
- firebase_app_check 0.3.2+5 [firebase_app_check_platform_interface firebase_app_check_web firebase_core firebase_core_platform_interface flutter]
- firebase_core 3.13.0 [firebase_core_platform_interface firebase_core_web flutter meta]
- firebase_kit 0.1.0 [flutter master_kit client_kit database_kit hive hive_flutter firebase_core firebase_auth firebase_crashlytics firebase_storage cloud_functions cloud_firestore firebase_database firebase_dynamic_links rxdart json_annotation http collection meta get_it app_links google_sign_in]
- firebase_remote_config 5.4.3 [firebase_core firebase_core_platform_interface firebase_remote_config_platform_interface firebase_remote_config_web flutter]
- firebase_vertexai 1.5.0 [firebase_app_check firebase_auth firebase_core firebase_core_platform_interface flutter http meta web_socket_channel]
- flutter 0.0.0 [characters collection material_color_utilities meta vector_math sky_engine]
- flutter_image_compress 2.4.0 [flutter flutter_image_compress_platform_interface flutter_image_compress_common flutter_image_compress_web flutter_image_compress_macos flutter_image_compress_ohos]
- flutter_launcher_icons 0.14.3 [args checked_yaml cli_util image json_annotation path yaml]
- flutter_local_notifications 19.0.0 [clock flutter flutter_local_notifications_linux flutter_local_notifications_windows flutter_local_notifications_platform_interface timezone]
- flutter_scroll_shadow 1.2.6 [flutter]
- get_it 7.7.0 [async collection meta]
- image_pixels 4.0.2 [flutter]
- infinite_scroll_pagination 4.1.0 [flutter flutter_staggered_grid_view sliver_tools]
- json_annotation 4.9.0 [meta]
- loading_indicator 3.1.1 [flutter async collection]
- master_kit 0.1.0+1 [rxdart diacritic universal_io collection meta get_it json_annotation async logger intl path]
- measure_size 4.0.0 [flutter]
- modal_bottom_sheet 3.0.0 [flutter]
- permission_handler 11.4.0 [flutter meta permission_handler_android permission_handler_apple permission_handler_html permission_handler_windows permission_handler_platform_interface]
- pull_to_refresh 2.0.0 [flutter]
- rxdart 0.27.7
- shimmer 3.0.0 [flutter]
- speech_to_text 7.0.0 [flutter speech_to_text_platform_interface json_annotation clock pedantic flutter_web_plugins meta web]
- super_sliver_list 0.4.1 [flutter collection logging]
- timezone 0.10.0 [http path]
- ui_kit 0.1.0 [flutter master_kit flutter_portal infinite_scroll_pagination flutter_svg flutter_svg_provider gradient_borders material_color_utilities rxdart collection shared_preferences super_sliver_list json_annotation]

dev dependencies:
- build_runner 2.4.15 [analyzer args async build build_config build_daemon build_resolvers build_runner_core code_builder collection crypto dart_style frontend_server_client glob graphs http http_multi_server io js logging meta mime package_config path pool pub_semver pubspec_parse shelf shelf_web_socket stack_trace stream_transform timing watcher web web_socket_channel yaml]
- flutter_lints 5.0.0 [lints]
- flutter_test 0.0.0 [flutter test_api matcher path fake_async clock stack_trace vector_math leak_tracker_flutter_testing async boolean_selector characters collection leak_tracker leak_tracker_testing material_color_utilities meta source_span stream_channel string_scanner term_glyph vm_service]
- json_serializable 6.9.0 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]

dependency overrides:
- json_annotation 4.9.0 [meta]
- json_serializable 6.9.0 [analyzer async build build_config collection json_annotation meta path pub_semver pubspec_parse source_gen source_helper]

transitive dependencies:
- _fe_analyzer_shared 76.0.0 [meta]
- _flutterfire_internals 1.3.54 [collection firebase_core firebase_core_platform_interface flutter meta]
- _macros 0.3.3
- analyzer 6.11.0 [_fe_analyzer_shared collection convert crypto glob macros meta package_config path pub_semver source_span watcher yaml]
- app_links 6.4.0 [flutter app_links_linux app_links_platform_interface app_links_web]
- app_links_linux 1.0.3 [flutter app_links_platform_interface gtk]
- app_links_platform_interface 2.0.2 [flutter plugin_platform_interface]
- app_links_web 1.0.4 [flutter flutter_web_plugins app_links_platform_interface web]
- archive 4.0.5 [crypto path posix]
- args 2.7.0
- async 2.11.0 [collection meta]
- boolean_selector 2.1.1 [source_span string_scanner]
- build 2.4.2 [analyzer async convert crypto glob logging meta package_config path]
- build_config 1.1.2 [checked_yaml json_annotation path pubspec_parse yaml]
- build_daemon 4.0.4 [built_collection built_value crypto http_multi_server logging path pool shelf shelf_web_socket stream_transform watcher web_socket_channel]
- build_resolvers 2.4.4 [analyzer async build collection convert crypto graphs logging package_config path pool pub_semver stream_transform yaml]
- build_runner_core 8.0.0 [async build build_config build_resolvers collection convert crypto glob graphs json_annotation logging meta package_config path pool timing watcher yaml]
- built_collection 5.1.1
- built_value 8.9.5 [built_collection collection fixnum meta]
- cached_network_image_platform_interface 4.1.1 [flutter flutter_cache_manager]
- cached_network_image_web 1.3.1 [cached_network_image_platform_interface flutter flutter_cache_manager web]
- characters 1.3.0
- checked_yaml 2.0.3 [json_annotation source_span yaml]
- cli_util 0.4.2 [meta path]
- clock 1.1.1
- cloud_firestore 5.6.6 [cloud_firestore_platform_interface cloud_firestore_web collection firebase_core firebase_core_platform_interface flutter meta]
- cloud_firestore_platform_interface 6.6.6 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- cloud_firestore_web 4.4.6 [_flutterfire_internals cloud_firestore_platform_interface collection firebase_core firebase_core_web flutter flutter_web_plugins]
- cloud_functions 5.4.0 [cloud_functions_platform_interface cloud_functions_web firebase_core firebase_core_platform_interface flutter]
- cloud_functions_platform_interface 5.6.5 [firebase_core flutter meta plugin_platform_interface]
- cloud_functions_web 4.10.11 [cloud_functions_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins]
- code_builder 4.10.1 [built_collection built_value collection matcher meta]
- convert 3.1.2 [typed_data]
- cross_file 0.3.4+2 [meta web]
- crypto 3.0.6 [typed_data]
- dart_style 2.3.8 [analyzer args collection package_config path pub_semver source_span]
- dbus 0.7.11 [args ffi meta xml]
- device_info_plus_platform_interface 7.0.2 [flutter meta plugin_platform_interface]
- diacritic 0.1.6
- email_validator 2.1.17
- fake_async 1.3.1 [clock collection]
- ffi 2.1.3
- file 7.0.1 [meta path]
- firebase_app_check_platform_interface 0.1.1+5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_app_check_web 0.2.0+9 [_flutterfire_internals firebase_app_check_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins web]
- firebase_auth 5.5.2 [firebase_auth_platform_interface firebase_auth_web firebase_core firebase_core_platform_interface flutter meta]
- firebase_auth_platform_interface 7.6.2 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_auth_web 5.14.2 [firebase_auth_platform_interface firebase_core firebase_core_web flutter flutter_web_plugins http_parser meta web]
- firebase_core_platform_interface 5.4.0 [collection flutter flutter_test meta plugin_platform_interface]
- firebase_core_web 2.22.0 [firebase_core_platform_interface flutter flutter_web_plugins meta web]
- firebase_crashlytics 4.3.5 [firebase_core firebase_core_platform_interface firebase_crashlytics_platform_interface flutter stack_trace]
- firebase_crashlytics_platform_interface 3.8.5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_database 11.3.5 [firebase_core firebase_core_platform_interface firebase_database_platform_interface firebase_database_web flutter]
- firebase_database_platform_interface 0.2.6+5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_database_web 0.2.6+11 [collection firebase_core firebase_core_web firebase_database_platform_interface flutter flutter_web_plugins]
- firebase_dynamic_links 6.1.5 [firebase_core firebase_core_platform_interface firebase_dynamic_links_platform_interface flutter meta plugin_platform_interface]
- firebase_dynamic_links_platform_interface 0.2.7+5 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_platform_interface 1.5.3 [_flutterfire_internals firebase_core flutter meta plugin_platform_interface]
- firebase_remote_config_web 1.8.3 [_flutterfire_internals firebase_core firebase_core_web firebase_remote_config_platform_interface flutter flutter_web_plugins]
- firebase_storage 12.4.5 [firebase_core firebase_core_platform_interface firebase_storage_platform_interface firebase_storage_web flutter]
- firebase_storage_platform_interface 5.2.5 [_flutterfire_internals collection firebase_core flutter meta plugin_platform_interface]
- firebase_storage_web 3.10.12 [_flutterfire_internals async firebase_core firebase_core_web firebase_storage_platform_interface flutter flutter_web_plugins http meta web]
- fixnum 1.1.1
- flutter_cache_manager 3.4.1 [clock collection file flutter http path path_provider rxdart sqflite uuid]
- flutter_image_compress_common 1.0.6 [flutter flutter_image_compress_platform_interface]
- flutter_image_compress_macos 1.0.3 [flutter flutter_image_compress_platform_interface]
- flutter_image_compress_ohos 0.0.3 [flutter flutter_image_compress_platform_interface]
- flutter_image_compress_platform_interface 1.0.5 [flutter plugin_platform_interface cross_file]
- flutter_image_compress_web 0.1.5 [flutter flutter_web_plugins flutter_image_compress_platform_interface web]
- flutter_local_notifications_linux 6.0.0 [dbus ffi flutter flutter_local_notifications_platform_interface path xdg_directories]
- flutter_local_notifications_platform_interface 9.0.0 [plugin_platform_interface]
- flutter_local_notifications_windows 1.0.0 [flutter ffi flutter_local_notifications_platform_interface meta timezone xml]
- flutter_portal 1.1.4 [collection flutter vector_math]
- flutter_staggered_grid_view 0.7.0 [flutter]
- flutter_svg 2.0.17 [flutter http vector_graphics vector_graphics_codec vector_graphics_compiler]
- flutter_svg_provider 1.0.7 [flutter http flutter_svg]
- flutter_web_plugins 0.0.0 [flutter characters collection material_color_utilities meta vector_math]
- frontend_server_client 4.0.0 [async path]
- glob 2.1.3 [async collection file path string_scanner]
- google_identity_services_web 0.3.3 [meta web]
- google_sign_in 6.3.0 [flutter google_sign_in_android google_sign_in_ios google_sign_in_platform_interface google_sign_in_web]
- google_sign_in_android 6.2.0 [flutter google_sign_in_platform_interface]
- google_sign_in_ios 5.8.1 [flutter google_sign_in_platform_interface]
- google_sign_in_platform_interface 2.5.0 [flutter plugin_platform_interface]
- google_sign_in_web 0.12.4+4 [flutter flutter_web_plugins google_identity_services_web google_sign_in_platform_interface http web]
- gradient_borders 1.0.1 [flutter]
- graphs 2.3.2 [collection]
- gtk 2.1.0 [ffi flutter meta]
- hive 2.2.3 [meta crypto]
- hive_flutter 1.1.0 [flutter hive path_provider path]
- http 1.3.0 [async http_parser meta web]
- http_multi_server 3.2.2 [async]
- http_parser 4.1.2 [collection source_span string_scanner typed_data]
- image 4.5.4 [archive meta xml]
- intl 0.19.0 [clock meta path]
- io 1.0.5 [meta path string_scanner]
- js 0.7.1
- leak_tracker 10.0.7 [clock collection meta path vm_service]
- leak_tracker_flutter_testing 3.0.8 [flutter leak_tracker leak_tracker_testing matcher meta]
- leak_tracker_testing 3.0.1 [leak_tracker matcher meta]
- lints 5.1.1
- logger 2.5.0
- logging 1.3.0
- macros 0.1.3-main.0 [_macros]
- matcher 0.12.16+1 [async meta stack_trace term_glyph test_api]
- material_color_utilities 0.11.1 [collection]
- meta 1.15.0
- mime 2.0.0
- octo_image 2.1.0 [flutter]
- package_config 2.2.0 [path]
- path 1.9.0
- path_parsing 1.1.0 [meta vector_math]
- path_provider 2.1.5 [flutter path_provider_android path_provider_foundation path_provider_linux path_provider_platform_interface path_provider_windows]
- path_provider_android 2.2.16 [flutter path_provider_platform_interface]
- path_provider_foundation 2.4.1 [flutter path_provider_platform_interface]
- path_provider_linux 2.2.1 [ffi flutter path path_provider_platform_interface xdg_directories]
- path_provider_platform_interface 2.1.2 [flutter platform plugin_platform_interface]
- path_provider_windows 2.3.0 [ffi flutter path path_provider_platform_interface]
- pedantic 1.11.1
- permission_handler_android 12.1.0 [flutter permission_handler_platform_interface]
- permission_handler_apple 9.4.6 [flutter permission_handler_platform_interface]
- permission_handler_html 0.1.3+5 [flutter flutter_web_plugins permission_handler_platform_interface web]
- permission_handler_platform_interface 4.3.0 [flutter meta plugin_platform_interface]
- permission_handler_windows 0.2.1 [flutter permission_handler_platform_interface]
- petitparser 6.0.2 [meta]
- platform 3.1.6
- plugin_platform_interface 2.1.8 [meta]
- pool 1.5.1 [async stack_trace]
- posix 6.0.1 [ffi meta path]
- pub_semver 2.2.0 [collection]
- pubspec_parse 1.5.0 [checked_yaml collection json_annotation pub_semver yaml]
- shared_preferences 2.5.3 [flutter shared_preferences_android shared_preferences_foundation shared_preferences_linux shared_preferences_platform_interface shared_preferences_web shared_preferences_windows]
- shared_preferences_android 2.4.8 [flutter shared_preferences_platform_interface]
- shared_preferences_foundation 2.5.4 [flutter shared_preferences_platform_interface]
- shared_preferences_linux 2.4.1 [file flutter path path_provider_linux path_provider_platform_interface shared_preferences_platform_interface]
- shared_preferences_platform_interface 2.4.1 [flutter plugin_platform_interface]
- shared_preferences_web 2.4.3 [flutter flutter_web_plugins shared_preferences_platform_interface web]
- shared_preferences_windows 2.4.1 [file flutter path path_provider_platform_interface path_provider_windows shared_preferences_platform_interface]
- shelf 1.4.2 [async collection http_parser path stack_trace stream_channel]
- shelf_web_socket 3.0.0 [shelf stream_channel web_socket_channel]
- sky_engine 0.0.0
- sliver_tools 0.2.12 [flutter]
- source_gen 1.5.0 [analyzer async build dart_style glob path source_span yaml]
- source_helper 1.3.5 [analyzer collection source_gen]
- source_span 1.10.0 [collection path term_glyph]
- speech_to_text_platform_interface 2.3.0 [flutter meta plugin_platform_interface]
- sprintf 7.0.0
- sqflite 2.4.1 [flutter sqflite_android sqflite_darwin sqflite_platform_interface sqflite_common path]
- sqflite_android 2.4.0 [flutter sqflite_common path sqflite_platform_interface]
- sqflite_common 2.5.4+6 [synchronized path meta]
- sqflite_darwin 2.4.1+1 [flutter sqflite_platform_interface meta sqflite_common path]
- sqflite_platform_interface 2.4.0 [flutter platform sqflite_common plugin_platform_interface meta]
- stack_trace 1.12.0 [path]
- stream_channel 2.1.2 [async]
- stream_transform 2.1.1
- string_scanner 1.3.0 [source_span]
- synchronized 3.3.0+3
- term_glyph 1.2.1
- test_api 0.7.3 [async boolean_selector collection meta source_span stack_trace stream_channel string_scanner term_glyph]
- timing 1.0.2 [json_annotation]
- typed_data 1.4.0 [collection]
- universal_io 2.2.2 [collection meta typed_data]
- uuid 4.5.1 [crypto sprintf meta fixnum]
- vector_graphics 1.1.18 [flutter http vector_graphics_codec]
- vector_graphics_codec 1.1.13
- vector_graphics_compiler 1.1.16 [args meta path path_parsing vector_graphics_codec xml]
- vector_math 2.1.4
- vm_service 14.3.0
- watcher 1.1.1 [async path]
- web 1.1.1
- web_socket 0.1.6 [web]
- web_socket_channel 3.0.2 [async crypto stream_channel web web_socket]
- win32 5.10.1 [ffi]
- win32_registry 1.1.5 [ffi win32]
- xdg_directories 1.1.0 [meta path]
- xml 6.5.0 [collection meta petitparser]
- yaml 3.1.3 [collection source_span string_scanner]

Additional context and comments

No response

@nrybarova nrybarova added Needs Attention This issue needs maintainer attention. type: bug Something isn't working labels Apr 24, 2025
@SelaseKay SelaseKay added platform: all Issues / PRs which are for all platforms. plugin: vertexai label issues for vertexai plugin labels Apr 24, 2025
@SelaseKay
Copy link
Contributor

Hi @nrybarova, thanks for the report. Could you provide a minimal repro for this issue?

@SelaseKay SelaseKay added blocked: customer-response Waiting for customer response, e.g. more information was requested. and removed Needs Attention This issue needs maintainer attention. labels Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked: customer-response Waiting for customer response, e.g. more information was requested. platform: all Issues / PRs which are for all platforms. plugin: vertexai label issues for vertexai plugin type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants