Skip to content

[Bug] GovDoc2Poster: basemodel.py ignores DASHSCOPE_API_KEY environment variable and uses hardcoded placeholder instead #530

Description

@SurbhiD404

[Bug] GovDoc2Poster: basemodel.py ignores DASHSCOPE_API_KEY environment variable and uses hardcoded placeholder instead

Description

GovDoc2Poster loads environment variables via load_dotenv() and instructs users to configure DASHSCOPE_API_KEY, but the environment variable is never read.

In basemodel.py:

load_dotenv()

# Prefer API key from environment for security and flexibility
self.api_key = "your_api"

Additionally, the code logs the following warning:

if not self.api_key:
    self.logger.warning(
        "DASHSCOPE API key is not set. Set DASHSCOPE_API_KEY env var or update basemodel.py"
    )

However, a repository-wide search shows no usage of os.getenv() in the GovDoc2Poster example, meaning the environment variable is never read.

The hardcoded placeholder value is then propagated to downstream OpenAI-based components, including:

  • NewGovernmentDocumentParser
  • NewGovernmentPosterPlanner
  • NewGovernmentPosterEvaluator

As a result, users who configure DASHSCOPE_API_KEY through environment variables cannot have it automatically picked up by the GovDoc2Poster pipeline.


Steps to Reproduce

  1. Set an environment variable:
$env:DASHSCOPE_API_KEY="test_key_123"
  1. Verify it is available:
echo $env:DASHSCOPE_API_KEY

Output:

test_key_123
  1. Search the GovDoc2Poster codebase:
git grep -n "os.getenv" examples/GovDoc2Poster
  1. Observe that no results are returned and basemodel.py always assigns:
self.api_key = "your_api"

Expected Behavior

When DASHSCOPE_API_KEY is configured, GovDoc2Poster should automatically read and use it.


Actual Behavior

The environment variable is ignored and the placeholder value "your_api" is propagated to downstream components.


Possible Fix

Read the API key from the environment and validate that a usable value is available:

self.api_key = kwargs.get(
    "api_key",
    os.getenv("DASHSCOPE_API_KEY", "")
)

if not self.api_key:
    raise ValueError(
        "API key not found. Set the DASHSCOPE_API_KEY "
        "environment variable or pass api_key as a parameter."
    )

This would make the implementation consistent with the existing warning message and the intended environment-variable-based configuration workflow.


Suggested Label

kind/bug

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions