Errors
Every non-2xx response from nl2sql-api is one envelope (packages/api/src/nl2sql_api/errors.py):
{"error": {"code": "NOT_FOUND", "message": "No datasource 'sales'.", "fix": "List the datasources with GET /api/v1/datasources.",
"details": [], "request_id": null}}
| Field | Meaning |
|---|---|
code |
A stable name: the facade exception's own code (APPROVAL_NOT_FOUND, DASHBOARD_BUSY, ...), or one of the API's own: UNAUTHENTICATED, FORBIDDEN, NOT_FOUND, CONFLICT, INVALID_REQUEST, INTERNAL. |
message |
One sentence a person can act on. |
fix |
What to do about it, when there is something to do. |
details |
422 only: one {"loc": [...], "msg": "..."} per problem. A rejected value is never echoed, because it may be a password. |
request_id |
500 only: the id the server logged the cause under. |
Every response, error or not, carries the id in the X-Request-ID header.
What becomes which status
- An
NL2SQLError(the base of every named facade exception) is answered with its ownstatusandcode: for exampleNotAuthorized403,ApprovalNotFound404,DashboardBusy409,InvalidArgument422. LockHeld(another save or run holds the same lease; it is not anNL2SQLError) is409CONFLICT, and the caller may retry.- A route or dependency that refuses on its own raises
RequestRefused(status, code, message, fix=..., details=...), with a message it wrote. - A body or parameter that does not validate is
422INVALID_REQUESTwithdetails. - An unknown route is
404NOT_FOUND; a wrong method is405. - Anything else is
500INTERNAL:"Something failed on the server. Request id: <id>". A built-inValueError,KeyError,LookupErrororPermissionError, or a pydanticValidationError, is never mapped to a 4xx, because its text may hold a connection string. The exception is logged with the id.
In an OpenAPI route, declare the envelope with responses={404: ERROR_RESPONSE} (from nl2sql_api.errors), or use
identity.AUTH_RESPONSES and identity.ADMIN_RESPONSES.
A conversation that is running a turn is a 409 (ConversationBusy); a refused conversation argument is a 422.
POST /api/v1/query is the exception for a pipeline failure: it is 200 with the errors in QueryResult.errors.