Skip to main content

Summary

Discovered a critical bug in yq-to-jq pipelines: yq (kislyuk v3.4.3) returns JSON strings with literal quote characters (\") preserved in the output. Piping directly to jq breaks: the quotes are part of the string value, not JSON delimiters. Solution: implement strip_quotes() bash helper to clean the output before JSON parsing. This pattern applies to any bash script using yq output as JSON input.

What changed operationally

Before: eval-traces.sh (H3) failed silently when scoring traces — jq would error or return wrong values because yq output contained escaped quotes. After: Applied strip_quotes() function (lines 45-50 in eval-traces.sh) to strip leading/trailing escaped quotes before piping to jq. All traces now score correctly. The fix:
strip_quotes() {
  sed 's/^\\"//;s/\\"$//'
}

# Usage:
yq '.output.result' trace.yaml | strip_quotes | jq '.field'
This is a one-off fix per yq call, not a global sed filter. Only strip where yq output flows directly to jq.

Business impact

  • H3 (trace evaluation) now produces accurate quality baselines (0.305-0.853 range validated)
  • H4 (campaign activation) gates work correctly based on accurate scores
  • H5-H8 refinement loop has correct baseline for regression detection
Without this fix, the entire H1-H8 pipeline would produce garbage quality scores, making all downstream decisions wrong.

Operational takeaway

yq is powerful but has sharp edges. Always test yq output before piping to jq. If yq -r output is feeding JSON consumers, add strip_quotes(). Document this in doctrines (BASH-EVAL-TRACE-PIPELINE.doctrine.md) for future bash maintainers.