Charset
Detect text encodings, convert legacy bytes to and from UTF-8, and repair mojibake
- Connector software
- Free and open source
- Service credentials
- Not needed
- Query Farm hosting
- Available · $10/month organization minimum
Use with an agent
Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.
npx skills add Query-farm/vgi-skills --skill orchard
Copy this request into your coding agent to get started.
Use https://query.farm/products/orchard/connectors/charset/index.md to help me query Charset with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.
See what you can query
Example output · captured
- Connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
WITH raw AS (SELECT id, charset.main.transcode(txt, enc) AS bytes FROM (VALUES (1, 'Grüße aus München', 'windows-1252'), (2, 'Привет, как дела?', 'windows-1251'), (3, 'こんにちは世界', 'shift_jis'), (4, 'naïve café', 'utf-8')) AS t(id, txt, enc)) SELECT id, charset.main.detect_encoding(bytes) AS detected, charset.main.detect_confidence(bytes) AS confidence, charset.main.is_valid_utf8(bytes) AS already_utf8, charset.main.to_utf8(bytes) AS text
FROM raw
ORDER BY id
| id | detected | confidence | already_utf8 | text |
|---|---|---|---|---|
| 1 | windows-1252 | 1 | false | Grüße aus München |
| 2 | windows-1251 | 1 | false | Привет, как дела? |
| 3 | Shift_JIS | 1 | false | こんにちは世界 |
| 4 | UTF-8 | 1 | true | naïve café |
Quick start
Choose where to run Charset, then follow the steps below.
The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.
1. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
2. Attach the connector
Attach the release directly
Downloads the latest release for your platform and caches it locally.
ATTACH 'charset' AS charset (
TYPE vgi,
LOCATION 'github-auto://Query-farm/vgi-charset'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'charset' AS charset (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-charset:0.5.0'
);
3. Run a query
WITH raw AS (SELECT id, charset.main.transcode(txt, enc) AS bytes FROM (VALUES (1, 'Grüße aus München', 'windows-1252'), (2, 'Привет, как дела?', 'windows-1251'), (3, 'こんにちは世界', 'shift_jis'), (4, 'naïve café', 'utf-8')) AS t(id, txt, enc)) SELECT id, charset.main.detect_encoding(bytes) AS detected, charset.main.detect_confidence(bytes) AS confidence, charset.main.is_valid_utf8(bytes) AS already_utf8, charset.main.to_utf8(bytes) AS text
FROM raw
ORDER BY id
Run the connector on a server you manage. You operate the service and choose who can connect.
1. Deploy the connector on your server
Follow the connector’s deployment instructions. Use its supported HTTP transport, or launch it remotely over SSH. The connection guide explains both options.
2. Install the vgi extension
Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach the connector
For an HTTP deployment, replace the example URL with your endpoint. Add the authentication options your deployment requires. For SSH, use the SSH connection instructions.
ATTACH 'charset' AS charset
(TYPE vgi, LOCATION 'https://your-connector.example.com');
4. Run a query
WITH raw AS (SELECT id, charset.main.transcode(txt, enc) AS bytes FROM (VALUES (1, 'Grüße aus München', 'windows-1252'), (2, 'Привет, как дела?', 'windows-1251'), (3, 'こんにちは世界', 'shift_jis'), (4, 'naïve café', 'utf-8')) AS t(id, txt, enc)) SELECT id, charset.main.detect_encoding(bytes) AS detected, charset.main.detect_confidence(bytes) AS confidence, charset.main.is_valid_utf8(bytes) AS already_utf8, charset.main.to_utf8(bytes) AS text
FROM raw
ORDER BY id
Query Farm operates Charset for your team. Hosting has a $10 monthly minimum per organization; usage counts toward it. From $2.97 per instance-month ($10 monthly minimum).
1. Create your hosted connector
Open the console, choose your organization and deployment size, and add any service credentials there.
2. Install the vgi extension
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;
INSTALL vgi FROM community;
LOAD vgi;
3. Attach your deployment
Copy the ATTACH statement from your deployment in the console and run it in DuckDB or Haybarn. Use charset as the catalog alias for the query below.
4. Run a query
WITH raw AS (SELECT id, charset.main.transcode(txt, enc) AS bytes FROM (VALUES (1, 'Grüße aus München', 'windows-1252'), (2, 'Привет, как дела?', 'windows-1251'), (3, 'こんにちは世界', 'shift_jis'), (4, 'naïve café', 'utf-8')) AS t(id, txt, enc)) SELECT id, charset.main.detect_encoding(bytes) AS detected, charset.main.detect_confidence(bytes) AS confidence, charset.main.is_valid_utf8(bytes) AS already_utf8, charset.main.to_utf8(bytes) AS text
FROM raw
ORDER BY id
Technical details
- Verified connector release
- v0.5.0
- Engine
- 2.0.1
- VGI protocol
- 3.4.0
- Verified on
- December 1, 2026
Pin a version for production
When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.
Attach the release directly
Uses the verified release each time you attach the connector.
ATTACH 'charset' AS charset (
TYPE vgi,
LOCATION 'github-auto://Query-farm/[email protected]'
);
Attach the signed image
Needs Docker, Podman or another OCI runtime. The extension runs the container and talks to it over stdio.
ATTACH 'charset' AS charset (
TYPE vgi,
LOCATION 'oci://ghcr.io/query-farm/vgi-charset:0.5.0'
);
Overview
Character-encoding detection and UTF-8 transcoding (mojibake repair).
Detect the character encoding of raw bytes and transcode legacy or mojibake-garbled text into clean UTF-8 directly in DuckDB SQL — no Python preprocessing step and no manual iconv passes.
What it does
charset is a VGI worker that adds character-encoding detection and UTF-8 transcoding to DuckDB over Apache Arrow. It is built for data engineers and analysts wrangling text of unknown or mixed provenance: CSV and log dumps in legacy Windows code pages, scraped HTML, email archives, and columns that arrived double-encoded — the classic Café-instead-of-Café mojibake. Rather than shelling out to external tools, you detect, repair, and normalize encodings inline with ordinary SQL queries.
How it works
Encoding detection is powered by Mozilla's chardetng (docs), the same heuristic Firefox applies to unlabelled legacy text. Decoding and encoding use encoding_rs (docs), the pure-Rust implementation of the WHATWG Encoding Standard that Firefox ships for every web-platform codec. A byte-order-mark (BOM) check runs first; undecodable bytes within a known encoding become the U+FFFD replacement character rather than raising an error, while an unknown encoding label is rejected so typos surface immediately.
When to reach for it
Reach for charset whenever a text column's bytes are of unknown, mixed, or legacy provenance: sniff the likely encoding and score how trustworthy that guess is, decode legacy bytes to UTF-8 either automatically or with an explicit codec label, re-encode UTF-8 back into a legacy codec for export, repair double-encoded mojibake, and check whether bytes are already clean UTF-8. Because detection is heuristic, confidence-check short or ambiguous samples before relying on a result. Empty or NULL input yields NULL everywhere.
Catalog
Everything charset exposes once attached — read straight from the worker's
released build.
main 1 table · 7 functions
Character-encoding detection and UTF-8 transcoding functions.
Schema examples (11)
Triage a column of unlabelled bytes in mixed legacy encodings (produced here with transcode): detect each row's encoding and confidence, flag which rows are already UTF-8, and decode every row to UTF-8 text.
WITH raw AS (SELECT id, charset.main.transcode(txt, enc) AS bytes FROM (VALUES (1, 'Grüße aus München', 'windows-1252'), (2, 'Привет, как дела?', 'windows-1251'), (3, 'こんにちは世界', 'shift_jis'), (4, 'naïve café', 'utf-8')) AS t(id, txt, enc)) SELECT id, charset.main.detect_encoding(bytes) AS detected, charset.main.detect_confidence(bytes) AS confidence, charset.main.is_valid_utf8(bytes) AS already_utf8, charset.main.to_utf8(bytes) AS text
FROM raw
ORDER BY id;
| id | detected | confidence | already_utf8 | text |
|---|---|---|---|---|
| 1 | windows-1252 | 1 | false | Grüße aus München |
| 2 | windows-1251 | 1 | false | Привет, как дела? |
| 3 | Shift_JIS | 1 | false | こんにちは世界 |
| 4 | UTF-8 | 1 | true | naïve café |
List the supported encodings that can store 'naïve café' losslessly: encode it into each label with transcode, decode it back with to_utf8_from, and keep the labels whose round trip is exact (the decode-only 'replacement' encoding has no encoder, so it is skipped).
SELECT label
FROM charset.main.supported_encodings
WHERE label <> 'replacement' AND charset.main.to_utf8_from(charset.main.transcode('naïve café', label), label) = 'naïve café'
ORDER BY label;
Before exporting names to a windows-1252 system, flag the ones that would not survive: encode each with transcode, decode the bytes back with to_utf8_from, and compare with the original.
SELECT name,
charset.main.to_utf8_from(charset.main.transcode(name, 'windows-1252'), 'windows-1252') = name AS fits_1252
FROM (VALUES ('Café Müller'), ('Łódź'), ('東京'), ('Smith')) AS t(name)
ORDER BY name;
Reproduce double-encoding mojibake (UTF-8 bytes from transcode misread as windows-1252 by to_utf8_from) and show fix_mojibake restoring the original text.
SELECT original,
charset.main.to_utf8_from(charset.main.transcode(original, 'utf-8'), 'windows-1252') AS garbled,
charset.main.fix_mojibake(garbled) AS repaired
FROM (VALUES ('Café'), ('Ünïcödé'), ('“smart quotes” — dash')) AS t(original)
ORDER BY original;
7 more examples
Detect the character encoding of windows-1252 bytes for "café".
SELECT charset.main.detect_encoding('\x63\x61\x66\xE9'::BLOB);
Auto-detect and decode windows-1252 bytes to a UTF-8 string.
SELECT charset.main.to_utf8('\x63\x61\x66\xE9'::BLOB);
Decode Shift-JIS bytes to UTF-8 with an explicit codec label.
SELECT charset.main.to_utf8_from('\x93\xFA\x96\x7B'::BLOB, 'shift_jis');
Encode a UTF-8 string into windows-1252 bytes for export.
SELECT charset.main.transcode('café', 'windows-1252');
Repair double-encoded mojibake back to clean UTF-8.
SELECT charset.main.fix_mojibake('Café');
Check whether bytes are already valid UTF-8.
SELECT charset.main.is_valid_utf8('\x63\x61\x66\xC3\xA9'::BLOB);
List the first few supported encoding labels.
SELECT label FROM charset.main.supported_encodings() ORDER BY label LIMIT 5;
supported_encodings
Every encoding label the worker accepts (the encoding_rs / WHATWG set of canonical encoding names).
List the first few supported encoding labels.
SELECT label FROM charset.main.supported_encodings ORDER BY label LIMIT 5;
Count how many encoding labels the worker accepts.
SELECT count(*) AS n FROM charset.main.supported_encodings;
List the supported encodings that can store 'naïve café' losslessly: encode it into each label with transcode, decode it back with to_utf8_from, and keep the labels whose round trip is exact (the decode-only 'replacement' encoding has no encoder, so it is skipped).
SELECT label
FROM charset.main.supported_encodings
WHERE label <> 'replacement' AND charset.main.to_utf8_from(charset.main.transcode('naïve café', label), label) = 'naïve café'
ORDER BY label;
9 more examples
SELECT charset.main.detect_encoding('\x63\x61\x66\xE9'::BLOB) AS encoding;
SELECT charset.main.to_utf8('\x63\x61\x66\xE9'::BLOB) AS text;
SELECT charset.main.to_utf8_from('\x93\xFA\x96\x7B'::BLOB, 'shift_jis') AS text;
SELECT charset.main.transcode('café', 'windows-1252') AS bytes;
SELECT charset.main.fix_mojibake('Café') AS fixed;
SELECT charset.main.is_valid_utf8('\x63\x61\x66\xC3\xA9'::BLOB) AS ok;
SELECT label FROM charset.main.supported_encodings() ORDER BY label LIMIT 5;
WITH raw AS (SELECT id, charset.main.transcode(txt, enc) AS bytes FROM (VALUES (1, 'Grüße aus München', 'windows-1252'), (2, 'Привет, как дела?', 'windows-1251'), (3, 'こんにちは世界', 'shift_jis'), (4, 'naïve café', 'utf-8')) AS t(id, txt, enc)) SELECT id, charset.main.detect_encoding(bytes) AS detected, charset.main.detect_confidence(bytes) AS confidence, charset.main.is_valid_utf8(bytes) AS already_utf8, charset.main.to_utf8(bytes) AS text
FROM raw
ORDER BY id;
| id | detected | confidence | already_utf8 | text |
|---|---|---|---|---|
| 1 | windows-1252 | 1 | false | Grüße aus München |
| 2 | windows-1251 | 1 | false | Привет, как дела? |
| 3 | Shift_JIS | 1 | false | こんにちは世界 |
| 4 | UTF-8 | 1 | true | naïve café |
SELECT original,
charset.main.to_utf8_from(charset.main.transcode(original, 'utf-8'), 'windows-1252') AS garbled,
charset.main.fix_mojibake(garbled) AS repaired
FROM (VALUES ('Café'), ('Ünïcödé'), ('“smart quotes” — dash')) AS t(original)
ORDER BY original;
detect_confidence (bytes BLOB)
A confidence proxy in [0,1] for the detected encoding, derived from whether the bytes decode losslessly (1.0) or required U+FFFD replacements (scaled down). NULL for empty/NULL input.
Score how confidently the bytes for "café" decode under the detected encoding (1.0 when lossless).
SELECT charset.main.detect_confidence('\x63\x61\x66\xE9'::BLOB);
detect_encoding (bytes BLOB)
Detect the character encoding of text bytes (BOM check, then the chardetng heuristic); returns the encoding label, e.g. 'UTF-8', 'windows-1252', 'Shift_JIS'. NULL for empty/NULL input.
Detect the encoding of the bytes for "café" stored as windows-1252 (returns 'windows-1252').
SELECT charset.main.detect_encoding('\x63\x61\x66\xE9'::BLOB);
Triage a column of unlabelled bytes in mixed legacy encodings (produced here with transcode): detect each row's encoding and confidence, flag which rows are already UTF-8, and decode every row to UTF-8 text.
WITH raw AS (SELECT id, charset.main.transcode(txt, enc) AS bytes FROM (VALUES (1, 'Grüße aus München', 'windows-1252'), (2, 'Привет, как дела?', 'windows-1251'), (3, 'こんにちは世界', 'shift_jis'), (4, 'naïve café', 'utf-8')) AS t(id, txt, enc)) SELECT id, charset.main.detect_encoding(bytes) AS detected, charset.main.detect_confidence(bytes) AS confidence, charset.main.is_valid_utf8(bytes) AS already_utf8, charset.main.to_utf8(bytes) AS text
FROM raw
ORDER BY id;
| id | detected | confidence | already_utf8 | text |
|---|---|---|---|---|
| 1 | windows-1252 | 1 | false | Grüße aus München |
| 2 | windows-1251 | 1 | false | Привет, как дела? |
| 3 | Shift_JIS | 1 | false | こんにちは世界 |
| 4 | UTF-8 | 1 | true | naïve café |
fix_mojibake (text VARCHAR)
Repair double-encoded mojibake (UTF-8 read as Latin-1/Windows-1252 then re-stored as UTF-8), e.g. 'Café' -> 'Café'. No-ops when it can't improve the text. NULL for NULL input.
Repair classic double-encoded mojibake, turning 'Café' back into 'Café'.
SELECT charset.main.fix_mojibake('Café');
Reproduce double-encoding mojibake (UTF-8 bytes from transcode misread as windows-1252 by to_utf8_from) and show fix_mojibake restoring the original text.
SELECT original,
charset.main.to_utf8_from(charset.main.transcode(original, 'utf-8'), 'windows-1252') AS garbled,
charset.main.fix_mojibake(garbled) AS repaired
FROM (VALUES ('Café'), ('Ünïcödé'), ('“smart quotes” — dash')) AS t(original)
ORDER BY original;
is_valid_utf8 (bytes BLOB)
Whether the bytes are already valid UTF-8. NULL for NULL input.
Check whether a BLOB already holds valid UTF-8 (returns true).
SELECT charset.main.is_valid_utf8('\x63\x61\x66\xC3\xA9'::BLOB);
to_utf8 (bytes BLOB)
Detect the encoding of text bytes and decode to a UTF-8 string (U+FFFD for undecodable bytes). NULL for empty/NULL input.
Auto-detect and decode windows-1252 bytes to the UTF-8 string "café".
SELECT charset.main.to_utf8('\x63\x61\x66\xE9'::BLOB);
to_utf8_from (bytes BLOB, encoding VARCHAR)
Decode text bytes using an EXPLICIT encoding label (no detection), e.g. to_utf8_from(b, 'shift_jis'). ERROR if the label is unknown; NULL for NULL bytes.
Decode Shift-JIS bytes to UTF-8 using an explicit codec label (returns "日本").
SELECT charset.main.to_utf8_from('\x93\xFA\x96\x7B'::BLOB, 'shift_jis');
transcode (text VARCHAR, to_encoding VARCHAR)
Encode a UTF-8 string into the named encoding's bytes (BLOB) for export, e.g. transcode('café', 'windows-1252'). Unmappable chars follow encoding_rs (HTML numeric refs for legacy codecs). ERROR on unknown label; NULL for NULL input.
Encode a UTF-8 string into windows-1252 bytes for export to a legacy system.
SELECT charset.main.transcode('café', 'windows-1252');
Before exporting names to a windows-1252 system, flag the ones that would not survive: encode each with transcode, decode the bytes back with to_utf8_from, and compare with the original.
SELECT name,
charset.main.to_utf8_from(charset.main.transcode(name, 'windows-1252'), 'windows-1252') = name AS fits_1252
FROM (VALUES ('Café Müller'), ('Łódź'), ('東京'), ('Smith')) AS t(name)
ORDER BY name;
Try these queries
List the supported encodings that can store 'naïve café' losslessly: encode it into each label with transcode, decode it back with to_utf8_from, and keep the labels whose round trip is exact (the decode-only 'replacement' encoding has no encoder, so it is skipped).
SELECT label
FROM charset.main.supported_encodings
WHERE label <> 'replacement' AND charset.main.to_utf8_from(charset.main.transcode('naïve café', label), label) = 'naïve café'
ORDER BY label
Before exporting names to a windows-1252 system, flag the ones that would not survive: encode each with transcode, decode the bytes back with to_utf8_from, and compare with the original.
SELECT name,
charset.main.to_utf8_from(charset.main.transcode(name, 'windows-1252'), 'windows-1252') = name AS fits_1252
FROM (VALUES ('Café Müller'), ('Łódź'), ('東京'), ('Smith')) AS t(name)
ORDER BY name
Detect the character encoding of windows-1252 bytes for "café".
SELECT charset.main.detect_encoding('\x63\x61\x66\xE9'::BLOB);
Uses detect_encoding
Auto-detect and decode windows-1252 bytes to a UTF-8 string.
SELECT charset.main.to_utf8('\x63\x61\x66\xE9'::BLOB);
Uses to_utf8
Encode a UTF-8 string into windows-1252 bytes for export.
SELECT charset.main.transcode('café', 'windows-1252');
Uses transcode
Repair double-encoded mojibake back to clean UTF-8.
SELECT charset.main.fix_mojibake('Café');
Uses fix_mojibake
13 more examples in the Catalog, each listed under the table or function it uses.
Questions it can answer
Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.
- What encoding does this worker detect for the UTF-8 byte representation of the text 'café'? Return only the single detected encoding label as one column.
- What encoding does this worker detect for the windows-1252 byte representation of the text 'café'? Return only the single detected encoding label as one column.
- Take the windows-1252 byte encoding of 'café' and decode it back into UTF-8 text.
- Repair the double-encoded mojibake string 'Café' into correct UTF-8.
- Treating the ASCII text 'hello' as raw bytes, does this worker consider them valid UTF-8? Return only the single boolean result as one column.
- How many distinct character encodings does this worker support?
Charset is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.
Related workers
Compress
File formats & encodings
Compress, decompress, and identify zstd, gzip, brotli, lz4, snappy, xz, and bzip2 payloads stored in BLOB columns
BSON
File formats & encodings
Query BSON documents and move them between files and tables
CBOR
File formats & encodings
Decode and encode CBOR and MessagePack, inspect security payloads, and import or export row files from SQL