fix(examples): exit non-zero when credentials are missing or nothing is listed
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.
| Example | Missing credentials | Empty catalog | StackOne errors |
|---|---|---|---|
langchain_integration.py | raise SystemExit | new guard | now caught in __main__ like the other examples |
langgraph_integration.py | raise SystemExit | new guard | already handled |
pydantic_ai_integration.py | raise SystemExit | new guards on the individual-tools and search-and-execute paths | now caught in __main__ like the other examples |
auth_management.py | raise SystemExit | the third section was already guarded; new guards on the first two | unchanged |
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:
| Example | Before | After |
|---|---|---|
| langchain_integration | exit 0 | exit 1, "Set STACKONE_API_KEY to run this example." |
| langgraph_integration | exit 0 | exit 1, same |
| pydantic_ai_integration | exit 0 | exit 1, same |
| auth_management | exit 0 | exit 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)
| Gate | Result |
|---|---|
| Repo skills | none in repo |
| /forge:forge | ran: 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 scan | security-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 security | 9fb20a8 (job 6e05b840): one medium, the LangChain handler printed response_body. Resolved in 31f4c6e, which prints str(exc); clean on 31f4c6e (job b2f55e81) |
| /security-review | ran: secrets, input validation, transport and DoS items clean; the server-side items do not apply to an SDK |
| /code-review | medium 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 |
| CI | green on 31f4c6e: 10 pass, 3 skipped |
| Unresolved review threads | 0 |
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, andauth_management.pynow raiseSystemExitfrom credential checks.- Adds empty-catalog guards to
langchain_integration.py,langgraph_integration.py, and the individual-tools path ofpydantic_ai_integration.py. langchain_integration.pynow catches StackOne API and toolset errors in__main__instead of letting them traceback.