Raise typed errors from OpenAIClient and BedrockClient

Aperta
#157 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
aws, python

Direzione di ricerca

Start with lettucedetect/detectors/llm_client.py and tests/test_llm_client_pytest.py; run the pytest command in the issue to see the current behavior. Check how provider exceptions and Bedrock replies are handled, then cover the listed error mappings, causes, and empty response in tests. Done means the mapped errors are raised, caller-owned LLMClient errors remain unwrapped, and the old behavior assertions are updated.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

ready-for-agent

Parent: #156 · Epic: #126 · Blocked by: #138
Branch from stateless_core; open the PR against it.

Problem

Provider failures surface as OpenAI's own exceptions, and an empty Bedrock reply returns "", which parses as "no hallucination found". A service can't tell its misconfiguration from a provider outage.

Current behavior

  • lettucedetect/detectors/llm_client.py:243 OpenAIClient.complete lets openai exceptions propagate.
  • llm_client.py:327-328 BedrockClient.complete logs "no tool-use block; returning empty result" and return "".
  • llm_client.py:230-241 OpenAIClient.__init__ reads OPENAI_API_KEY and OPENAI_API_BASE and falls back to "EMPTY" (leave as is; the LLM-call layer replaces it).

Steps

  1. In OpenAIClient.complete, map authentication and quota errors to ConfigurationError (authentication_failed, quota_exceeded) and timeouts, connection errors, rate limits and server errors to UpstreamError (upstream_unavailable). Chain with raise ... from.
  2. In BedrockClient.complete, raise UpstreamError (empty_response) when the reply has no tool-use block instead of returning "".
  3. Errors from a caller's own LLMClient must propagate unwrapped (no wrapping in detectors).
  4. Don't log and raise the same error.

Acceptance criteria

  • Tests with a fake openai client raising each OpenAI error class check the mapped class, code and __cause__.
  • A Bedrock reply with no tool call raises UpstreamError (empty_response); the test uses pytest.importorskip("boto3") only if it needs boto3.
  • tests/test_llm_client_pytest.py is updated only where it asserted the old "" or raw-exception behavior (an intended change; say so in the PR).

Start here

uv run --extra dev pytest tests/test_llm_client_pytest.py -q
Lingua principale
Python
Stelle
615
Fork
60
Merge medio
1g 8h
PR unite (30g)
10

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di KRLabsOrg/LettuceDetect

Tutte le issue di KRLabsOrg/LettuceDetect

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.