The vulnerability lies in the _validate_query method of the SQLChatAgent class in the langroid library. The method's purpose is to prevent SQL injection and the execution of dangerous SQL functions. However, the initial implementation relied solely on a regular expression to identify and block these functions. The regex was not comprehensive enough and could be bypassed by crafting SQL queries with quoted function names, inline comments, or schema-qualified function names. This bypass allowed an attacker to execute harmful functions like pg_read_file, which can read files from the server's filesystem, compromising its confidentiality. The patch addresses this by introducing a more robust validation mechanism. After the initial regex check, the query is parsed into an Abstract Syntax Tree (AST). The AST is then traversed to identify all function calls. The names of these functions are normalized (unquoted, schema-stripped, and case-folded) and checked against a blocklist of dangerous function names and prefixes. This AST-based validation is not susceptible to the bypass techniques that affected the regex-based approach, thus effectively mitigating the vulnerability.