rohitg00/ai-engineering-from-scratch · error · RuntimeError

required secret {name} is not configured

Error message

required secret {name} is not configured

What it means

Error "required secret {name} is not configured" thrown in rohitg00/ai-engineering-from-scratch.

Source

Thrown at certifications/claude/lessons/13-application-security-and-secrets/code/main.py:110

        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__":
    print(json.dumps(demo(), indent=2))

View on GitHub (pinned to 39ea8a1c6d)

When it happens

Trigger: Thrown at certifications/claude/lessons/13-application-security-and-secrets/code/main.py:110 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/3cd2c684040164bd. Report an issue: GitHub.