fix(examples): exit non-zero when credentials are missing or nothing is listed

Merged
GL
8d ago
+53-39

What

CLAUDE.md says each example "must fail loudly rather than succeed with an empty catalog". Four examples printed "Set X to run this example." and returned, so they exited 0, and only auth_management.py checked for an empty tool list, in one of its three sections. They now behave like openai_integration.py already does.

ExampleMissing credentialsEmpty catalogStackOne errors
langchain_integration.pyraise SystemExitnew guardnow caught in __main__ like the other examples
langgraph_integration.pyraise SystemExitnew guardalready handled
pydantic_ai_integration.pyraise SystemExitnew guards on the individual-tools and search-and-execute pathsnow caught in __main__ like the other examples
auth_management.pyraise SystemExitthe third section was already guarded; new guards on the first twounchanged

account_id is now read with os.environ[...] after the check, so ty sees a str.

How verified

Each example run with no credentials, before and after:

ExampleBeforeAfter
langchain_integrationexit 0exit 1, "Set STACKONE_API_KEY to run this example."
langgraph_integrationexit 0exit 1, same
pydantic_ai_integrationexit 0exit 1, same
auth_managementexit 0exit 1, "STACKONE_API_KEY is not set. ..."

With only STACKONE_ACCOUNT_ID missing, all four exit 1 naming that variable. ruff check, ruff format --check and ty check stackone_ai examples pass. The empty-catalog guards were not exercised against a live key.

Gates (head 31f4c6e)

GateResult
Repo skillsnone in repo
/forge:forgeran: 9fb20a8 dropped an unused variable and aligned the guards; re-run on 31f4c6e: 0 comment lines, 2 copies (the identical __main__ handlers each standalone example needs, same count as before the review fixes)
Security scansecurity-reviewer agent: no finding at confidence 70 or above. Aikido: 31 open issues on main (lockfile CVEs, workflow SAST, one old test-fixture secret), none on lines this PR changes
Codex security9fb20a8 (job 6e05b840): one medium, the LangChain handler printed response_body. Resolved in 31f4c6e, which prints str(exc); clean on 31f4c6e (job b2f55e81)
/security-reviewran: secrets, input validation, transport and DoS items clean; the server-side items do not apply to an SDK
/code-reviewmedium on 9fb20a8, 8 candidates. Fixed 6: the search and execute half of the Pydantic AI example and the first two auth_management sections fail on an empty catalog, the Pydantic AI example handles StackOne errors, the LangChain and LangGraph handlers catch StackOneError (so ToolArgumentsError is covered) and no longer call a listing failure a rejected tool call, and an unknown tool name in a LangChain tool call exits instead of being skipped. Declined 2: the env guard and empty-catalog message are repeated per file on purpose, since each example runs on its own
CIgreen on 31f4c6e: 10 pass, 3 skipped
Unresolved review threads0

Requested by guillaume@stackone.com in Slack (repo audit thread).

šŸ¤– Generated with Claude Code


Summary by cubic

Makes the example scripts fail loudly when credentials are missing or the account serves no tools, instead of exiting 0 with a printed message.

  • langchain_integration.py, langgraph_integration.py, pydantic_ai_integration.py, and auth_management.py now raise SystemExit from credential checks.
  • Adds empty-catalog guards to langchain_integration.py, langgraph_integration.py, and the individual-tools path of pydantic_ai_integration.py.
  • langchain_integration.py now catches StackOne API and toolset errors in __main__ instead of letting them traceback.