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

オープン 初心者向け
#334 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
77/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
backend, databases

調査の方向性

src/selfgraph/resolution.py の LLMResolver.resolve から始め、issue によると dict 形式の応答を受け付ける _checked_output と、応答の処理を比較してください。resolver の動作と無効な LLM 出力に関する既存のテストを確認し、same が非 boolean 値の場合と、dict 形式または欠落した応答の場合のテストを追加してください。無効な応答でコード invalid_llm_output の ExtractionError が発生し、有効な応答は引き続き正しく解決されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
TypeScript
スター
173
フォーク
58
平均マージ
6時間
マージ済み PR(30日)
120

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

hydra-db/selfgraph のほかの issue

hydra-db/selfgraph の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。