Skip to content

PromptGuardian crashes if GOOGLE_API_KEY env var is invalid #4

Description

@vhosakot

PromptGuardian crashes if GOOGLE_API_KEY env var is invalid like below:

GOOGLE_API_KEY=junk1234

PG logs:

ERROR:    Traceback (most recent call last):
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 734, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 610, in __aenter__
    await self._router.startup()
  File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 711, in startup
    await handler()
  File "/usr/local/lib/python3.11/site-packages/prompt_guardian/server.py", line 76, in startup_event
    if prompt_guardian_app.state.gemini_prompt_guard.chat is None:
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'GeminiPromptGuard' object has no attribute 'chat'
ERROR:    Application startup failed. Exiting.

It'd be nice if PG prints an error in logs, similar to the below error seen in PG logs when OPENAI_API_KEY env var is invalid like OPENAI_API_KEY= junk1234:

Error code: 401 - {'error': {'message': 'Incorrect API key provided: junk1234. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions