rohitg00/ai-engineering-from-scratch · error · ValueError
secret name must be an uppercase environment variable
Error message
secret name must be an uppercase environment variable
What it means
Error "secret name must be an uppercase environment variable" thrown in rohitg00/ai-engineering-from-scratch.
Source
Thrown at certifications/claude/lessons/13-application-security-and-secrets/code/main.py:107
if not isinstance(url, str):
return Decision(False, "url must be a string", ("schema_validation",))
parsed = urlparse(url)
if parsed.scheme != "https" or parsed.hostname not in self.allowed_hosts:
return Decision(False, "network destination is not allowed", ("network_allowlist",))
return Decision(True, "read-only request to allowed host", ("network_allowlist", "response_size_limit"))
def redact(value: str) -> str:
"""Remove common secret assignments before a string reaches logs."""
return SECRET_VALUE_PATTERN.sub(lambda match: f"{match.group(1)}=[REDACTED]", value)
class EnvironmentSecrets:
"""Return secret values to trusted code without logging or serialization helpers."""
def require(self, name: str) -> str:
if not re.fullmatch(r"[A-Z][A-Z0-9_]+", name):
raise ValueError("secret name must be an uppercase environment variable")
value = os.environ.get(name)
if not value:
raise RuntimeError(f"required secret {name} is not configured")
return value
def demo() -> dict[str, Any]:
gate = PolicyGate(["/workspace/project"], ["api.example.test"])
actions = [
Action("read_file", {"path": "/workspace/project/README.md"}),
Action("read_file", {"path": "/workspace/project/.env"}),
Action("run_command", {"command": "rm -rf /workspace/project"}, approved=True),
Action("http_get", {"url": "https://api.example.test/status"}),
]
return {"decisions": [decision.__dict__ for decision in map(gate.evaluate, actions)]}
if __name__ == "__main__":View on GitHub (pinned to 39ea8a1c6d)
When it happens
Trigger: Thrown at certifications/claude/lessons/13-application-security-and-secrets/code/main.py:107 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of rohitg00/ai-engineering-from-scratch@39ea8a1c6d (2026-08-26).
Data as JSON: /api/errors/69d3a81dd7e2cd06.
Report an issue: GitHub.