Fixing 'Could not open ollama/ollama-curated.yaml' in AI::Ollama::Client
Original question: AI::Ollama::Client and 'ollama/ollama-curated.yaml'
The error "Could not open 'ollama/ollama-curated.yaml' for reading" occurs because the AI::Ollama::Client distribution on CPAN ships the file ollama/ollama-curated.yaml in the distro archive but does not install it to the expected location during cpan install. This is a confirmed bug in the distribution, and a ticket has been filed. The immediate fix is to manually copy the YAML schema file from the distribution into your project directory and load it explicitly using YAML::PP when constructing the client object.
The Full Answer
Understanding the Problem
The AI::Ollama::Client Perl module provides a client interface to the Ollama API, which runs local large language models. The module relies on a YAML schema file (ollama-curated.yaml) to validate and structure API requests and responses. This file is included in the distribution tarball on CPAN, but the module's build script (Makefile.PL or Build.PL) does not have instructions to copy it into the Perl site library during installation. As a result, when the module tries to open the file at runtime using a relative path like ollama/ollama-curated.yaml, the file is not found, and Perl throws a fatal error from YAML::PP::Lexer.
The error message you see is:
Could not open 'ollama/ollama-curated.yaml' for reading: No such file or directory at .../YAML/PP/Lexer.pm line 141.
This happens because the module's default constructor expects the schema file to be in a subdirectory named ollama relative to the current working directory, or in a location relative to the module's installation path. Since the file was never installed, neither location works.
Workaround: Manual Schema Loading
The accepted solution, provided by ikegami on Stack Overflow, is to manually copy the YAML file from the distribution into your project and load it explicitly. This bypasses the broken default path resolution.
Step-by-Step Instructions
-
Locate the distribution tarball on your system. If you installed AI::Ollama::Client via CPAN, the tarball is typically cached in
~/.cpan/sources/authors/id/orC:\Dev\Perl\strawberry-perl-5.38.2.2-64bit-portable\cpan\sources\authors\id\on Strawberry Perl. The exact path depends on your CPAN configuration. You can also download the latest version from MetaCPAN. -
Extract the tarball and find the file
ollama/ollama-curated.yamlinside the distribution directory. -
Copy the file into your project root directory (or a subdirectory like
schema/). For this example, we'll place it in the project root. -
Modify your Perl script to load the schema manually using YAML::PP and pass it to the AI::Ollama::Client constructor. Here is the complete code:
use strict;
use warnings;
use AI::Ollama::Client qw( );
use FindBin qw( $RealBin );
use YAML::PP qw( );
my $yaml_parser = YAML::PP->new( boolean => 'JSON::PP' );
my $schema = $yaml_parser->load_file( "$RealBin/ollama-curated.yaml" );
my $client = AI::Ollama::Client->new(
server => 'http://127.0.0.1:11434',
schema => $schema,
);
my $info = $client->listModels()->get;
for my $model ($info->models->@*) {
say $model->model;
}
Explanation of the code:
use FindBin qw( $RealBin );gives you the absolute path to the directory containing your script. This ensures the YAML file is found regardless of the current working directory.YAML::PP->new( boolean => 'JSON::PP' )creates a YAML parser that uses JSON::PP for boolean handling, which matches what AI::Ollama::Client expects internally.$yaml_parser->load_file( "$RealBin/ollama-curated.yaml" )reads the YAML file and returns a Perl data structure (a hash reference).- The
schemaparameter in the constructor overrides the default schema loading behavior, so the module uses your manually loaded schema instead of trying to open the missing file.
- Run your script from the project directory. The script should now work without the file-not-found error.
Alternative: Patch the Distribution
If you prefer a permanent fix for your Perl installation, you can manually copy the YAML file into the expected location. On Strawberry Perl, the module's library path is something like:
C:/Dev/Perl/strawberry-perl-5.38.2.2-64bit-portable/perl/site/lib/AI/Ollama/Client/
Create a subdirectory named ollama inside that path and place ollama-curated.yaml there. Then the default constructor should find it. However, this is not recommended because it will be overwritten the next time you upgrade the module, and it does not fix the underlying distribution bug.
When to Use Each Approach
- Manual schema loading (recommended): Use this for individual projects or scripts. It is self-contained, does not modify your Perl installation, and works immediately. It also makes your script portable: you can bundle the YAML file with your code and distribute it to other systems.
- Patching the installation: Use this only if you have many scripts that all use AI::Ollama::Client and you want a global fix. Be aware that future module updates will revert this change.
Common Pitfalls
- File path issues: If you place the YAML file in a subdirectory (e.g.,
schema/ollama-curated.yaml), update the path inload_fileaccordingly:"$RealBin/schema/ollama-curated.yaml". The script will fail if the path is wrong. - YAML::PP not installed: The workaround requires YAML::PP. If you don't have it, install it with
cpan YAML::PPorcpanm YAML::PP. It is a dependency of AI::Ollama::Client, so it should already be present. - Boolean handling mismatch: The
boolean => 'JSON::PP'option is important. If you omit it or use a different boolean module, the schema may not parse correctly, leading to subtle bugs in API calls. - Community-reported caveat: Some users on Stack Overflow reported that the schema file in the distribution might be outdated compared to the Ollama API. If you encounter unexpected validation errors, check the Ollama API documentation and consider updating the schema manually.
- Windows path separators: On Windows, the path
"$RealBin/ollama-curated.yaml"works because Perl'sFindBinreturns forward slashes. If you use backslashes, escape them properly.
Related Questions
How do I check if the YAML file is actually missing from my installation?
Run the following command in a terminal: perl -MAI::Ollama::Client -e "print $INC{'AI/Ollama/Client.pm'}". This prints the path to the module. Then navigate to that directory and look for a subdirectory named ollama. If it does not exist, or if ollama-curated.yaml is not inside it, the file is missing. You can also search your entire Perl site library for the file: find C:/Dev/Perl -name "ollama-curated.yaml" on Windows (using Git Bash or WSL) or locate ollama-curated.yaml on Linux.
Can I use a different YAML parser instead of YAML::PP?
Yes, but it is not recommended. AI::Ollama::Client internally uses YAML::PP to load the schema, so using a different parser (like YAML::XS or YAML::Tiny) may produce a data structure that is not compatible with the module's expectations. If you must use another parser, ensure it returns a hash reference with the same keys and structure. Stick with YAML::PP to avoid compatibility issues.
Will this bug be fixed in a future version of AI::Ollama::Client?
A bug ticket has been filed with the module maintainer, as confirmed by the Stack Overflow answer. The fix would involve updating the distribution's build script to install the YAML file to the correct location. Until a new version is released, the workaround described here is the only reliable solution. You can monitor the module's CPAN page or GitHub repository for updates.
What if I don't have the distribution tarball anymore?
You can download the latest version from MetaCPAN: https://metacpan.org/dist/AI-Ollama-Client. Click the "Download" link to get the tarball. Alternatively, you can extract the YAML file directly from the installed module's .pm files if the schema is embedded, but it is not in this case. The file is only in the distribution archive.
The #1 AI Newsletter
The most important ai updates, guides, and fixes โ one weekly email.
No spam, unsubscribe anytime. Privacy policy
Sources & References
This page was researched from 2 independent sources, combined and verified for completeness.
- 1.Answer by ikegami (score 3, accepted)Stack Overflow ยท primary source
- 2.AI::Ollama::Client and 'ollama/ollama-curated.yaml'Stack Overflow
Related Answers
Keep exploring
Latest error solutions
Skip the manual work
Ready-made AI workflows and automation templates โ import and run instead of building from scratch.