resolver="llm" merges on a non-bool reply and raises AttributeError on a dict

Aperta Adatta ai principianti
#334 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend, databases

Direzione di ricerca

Inizia da src/selfgraph/resolution.py, in LLMResolver.resolve, e confronta la gestione della risposta con _checked_output, che, secondo quanto indicato dall’issue, accetta risposte dict. Esamina i test esistenti sul comportamento del resolver e sugli output LLM non validi, poi aggiungi test per un valore non booleano di same e per risposte dict o mancanti. Il lavoro è completato quando le risposte non valide generano ExtractionError con il codice invalid_llm_output e quelle valide continuano a essere risolte correttamente.

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

Descrizione

approved-for-pr area: errors area: extraction bug effort: S P2

What happens

LLMResolver reads answer.same from the client's reply and branches on its truthiness. Nothing validates the reply:

  • A reply whose same is a non-empty string such as "no" or "false" merges the two entities.
  • A dict reply ({"same": False}), None, or an object without same raises a raw AttributeError out of insert.facts / insert.text, not a SelfGraphError.

The extraction path accepts dict replies (_checked_output validates them), so a client that returns dicts works for extraction and breaks resolution.

Reproduce

On main (5a277c9), embedded Kuzu. "Globex" and "Globex Systems" score 0.886, inside the default band, so the resolver asks the LLM.

import asyncio, tempfile
from types import SimpleNamespace
from selfgraph import KuzuStore, SelfGraph

class LLM:
    def __init__(self, reply):
        self.reply = reply

    async def generate(self, *, system, user, output):
        return self.reply if output.__name__ == "_SameEntity" else output()

async def run(reply):
    with tempfile.TemporaryDirectory() as tmp:
        async with SelfGraph(store=KuzuStore(f"{tmp}/g.kuzu"), llm=LLM(reply), resolver="llm") as g:
            await g.insert.facts({"entities": [{"type": "Person", "name": "Globex"}]})
            try:
                r = await g.insert.facts({"entities": [{"type": "Person", "name": "Globex Systems"}]})
                print(repr(reply), "merges:", [(m.absorbed_id, m.survivor_id) for m in r.merges])
            except Exception as exc:
                print(repr(reply), type(exc).__name__, exc)

for reply in [SimpleNamespace(same="no"), {"same": False}, None]:
    asyncio.run(run(reply))

Output:

namespace(same='no') merges: [('person:globex-systems', 'person:globex')]
{'same': False} AttributeError 'dict' object has no attribute 'same'
None AttributeError 'NoneType' object has no attribute 'same'

Cause

src/selfgraph/resolution.py, LLMResolver.resolve: answer = await self._llm.generate(...) then if answer.same:. It should validate the reply as _SameEntity (strict bool, accepting a mapping or attributes as extraction does) and raise ExtractionError with code invalid_llm_output when it cannot.

Lingua principale
TypeScript
Stelle
173
Fork
58
Merge medio
6h
PR unite (30g)
120

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 hydra-db/selfgraph

Tutte le issue di hydra-db/selfgraph

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.