# Issue with UTF-8 in yaml\_read

**URL:** <https://swi-prolog.discourse.group/t/issue-with-utf-8-in-yaml-read/9879>\
**Category:** General\
**Tags:** bug\
**Created:** [November 1, 2026, 9:16pm UTC](https://swi-prolog.discourse.group/t/issue-with-utf-8-in-yaml-read/9879 "2026-11-01T21:16:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wdiestel](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/wdiestel/32/22_2.png) [@wdiestel](https://swi-prolog.discourse.group/u/wdiestel)\
**Post date:** [November 1, 2026, 9:16pm UTC](https://swi-prolog.discourse.group/t/issue-with-utf-8-in-yaml-read/9879/1 "2026-11-01T21:16:20Z")

</div>

Hello,

I have issues parsing an UTF-8-YAML string using yaml\_read. Do I miss something or is it a bug?  
I use Ubuntu and currently have this libyaml version installed:

libyaml-0-2/noble,now 0.2.5-1build1 amd64 [Installiert,automatisch]

Kind regards,  
Wolfram.

```prolog
$ swipl
Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4)
%...

[trace] ?- yaml_read(string("name: Kovacs"),Yaml).
   Call: (10) yaml:yaml_read(string("name: Kovacs"), _1326) ? up
Yaml = yaml{name:"Kovacs"}.

[trace] ?- yaml_read(string("name: Kovács"),Yaml).
   Call: (10) yaml:yaml_read(string("name: Kovács"), _4448) ? up
ERROR: Unknown error term: yaml_error(2,"invalid trailing UTF-8 octet")
ERROR: In:
ERROR: [13] yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60),_6630)
ERROR: [12] setup_call_catcher_cleanup(yaml:yaml_open(...,<stream>(0x61fe3cd67c60),...),yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60),_6686),_6658,yaml:close(<stream>(0x61fe3cd67c60))) at /usr/lib/swi-prolog/boot/init.pl:679
ERROR: [11] setup_call_cleanup(yaml:yaml_open(...,<stream>(0x61fe3cd67c60),...),yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60),_6750),yaml:close(<stream>(0x61fe3cd67c60))) at /usr/lib/swi-prolog/boot/init.pl:682
ERROR: [10] yaml:yaml_read(string("name: Kovács"),_6792) at /usr/lib/swi-prolog/library/yaml.pl:96
ERROR: [9] toplevel_call(user:user: ...) at /usr/lib/swi-prolog/boot/toplevel.pl:1173
   Exception: (13) yaml:yaml_parse_stream(<stream>(0x61fe3cd67c60), _5824) ? abort
% Execution Aborted

```

```prolog
$ echo "Kovács" | hexdump -C
00000000 4b 6f 76 c3 a1 63 73 0a |Kov..cs.|

```

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [November 2, 2026, 8:56am UTC](https://swi-prolog.discourse.group/t/issue-with-utf-8-in-yaml-read/9879/2 "2026-11-02T08:56:17Z")

</div>

> [@wdiestel](#):
>
> Do I miss something or is it a bug?

Surely is a bug 🙂 Fixed. Pushed a fix to GIT. You could install from PPA after the next release, build from source or use this Claude generated work-around:

```prolog
:- use_module(library(yaml)).
:- use_module(library(memfile)).

yaml_read_string(String, DOM) :-
    setup_call_cleanup(
        new_memory_file(MF),
        ( setup_call_cleanup(
              open_memory_file(MF, write, Out, [encoding(utf8)]),
              write(Out, String),
              close(Out)),
          setup_call_cleanup(
              open_memory_file(MF, read, In, [encoding(octet)]),
              yaml_read(In, DOM),
              close(In))),
        free_memory_file(MF)).

```

---

<div class="post-metadata">

**Author:** ![wdiestel](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/wdiestel/32/22_2.png) [@wdiestel](https://swi-prolog.discourse.group/u/wdiestel)\
**Post date:** [November 2, 2026, 4:52pm UTC](https://swi-prolog.discourse.group/t/issue-with-utf-8-in-yaml-read/9879/3 "2026-11-02T16:52:59Z")

</div>

Thank you! I like the suggested workaround 🙂

Kind regards,  
Wolfram.
