compare-models: synastry input; reject placeholder strings in answers
- worker compare-models --synastry FILE takes a /v1/synastry response and writes a relationship analysis. - Answer validation now needs at least three letters per string, so a placeholder title such as "x" (seen from Opus 5.5) triggers a retry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -170,7 +170,8 @@ pub fn build(kind: Kind, language: &str, chart_text: &str) -> Prompt {
|
||||
}
|
||||
|
||||
/// Checks an answer against our schema subset (objects with required
|
||||
/// properties, non-empty strings, string arrays with at least two items).
|
||||
/// properties, strings with at least three letters, string arrays with at
|
||||
/// least two items). A placeholder such as "x" counts as missing.
|
||||
pub fn validate(schema: &Value, value: &Value) -> Result<(), String> {
|
||||
fn walk(schema: &Value, value: &Value, path: &str) -> Result<(), String> {
|
||||
match schema["type"].as_str() {
|
||||
@@ -190,7 +191,7 @@ pub fn validate(schema: &Value, value: &Value) -> Result<(), String> {
|
||||
items.iter().enumerate().try_for_each(|(i, v)| walk(&schema["items"], v, &format!("{path}[{i}]")))
|
||||
}
|
||||
Some("string") => match value.as_str() {
|
||||
Some(s) if !s.trim().is_empty() => Ok(()),
|
||||
Some(s) if s.chars().filter(|c| c.is_alphabetic()).nth(2).is_some() => Ok(()),
|
||||
_ => Err(format!("{path}: expected a non-empty string")),
|
||||
},
|
||||
_ => Ok(()),
|
||||
@@ -260,6 +261,21 @@ pub fn to_markdown(kind: Kind, language: &str, content: &Value) -> String {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn validate_rejects_placeholder_titles() {
|
||||
let schema = schema(Kind::Synastry);
|
||||
let section = json!({"title": "Rák-szívek", "body": "Két bekezdés szöveg."});
|
||||
let mut answer = json!({
|
||||
"title": "Két Rák-szív", "summary": "Összefoglaló.", "advice": "Útravaló.",
|
||||
"strengths": ["Egyik erősség.", "Másik erősség."], "challenges": ["Egy kihívás.", "Még egy."],
|
||||
"sections": {"attraction": section, "communication": section, "emotional_bond": section,
|
||||
"friction": section, "long_term": section},
|
||||
});
|
||||
assert_eq!(validate(&schema, &answer), Ok(()));
|
||||
answer["sections"]["attraction"]["title"] = json!("x");
|
||||
assert_eq!(validate(&schema, &answer), Err("$.sections.attraction.title: expected a non-empty string".into()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polish_turns_straight_quotes_hungarian() {
|
||||
let mut v = json!({"a": "a \"hazai pálya\" és a \"sorok\"", "b": ["egy \" pár nélkül"], "c": {"d": "nincs"}});
|
||||
|
||||
Reference in New Issue
Block a user