Building a News Article Triage Pipeline with Jev and Python
From the publisher’s feed, collected in the ZeroLabs newsroom.
A news assistant should not scrape every result returned by a search engine. That is expensive, slow, and often produces noisy answers. A better design is to separate discovery from investigation:Fetch a small set of current article headlines.Score every headline against the user’s question.Shortlist the strongest candidates.Use a categorical choice to select one article.Use a yes/no probability to decide whether the selected article is worth scraping.This article demonstrates that pattern with Jev, TypeSafe’s structured decision model, and a Google News RSS helper.Why use three question types?Jev provides three useful primitives:Score places an item on an ordered scale.Choice selects one item from a fixed set.Noul estimates the probability that a yes/no statement is true.These primitives have different jobs in the pipeline. A score is useful for ranking all candidates. A choice is useful for making one final selection from a smaller set. A Noul is useful as a confidence gate before taking an expensive action such as scraping an article.The pipelineThe important design detail is sequencing. We do not ask Jev to choose an article and evaluate that same choice in one request. Questions in one request are evaluated independently and in parallel. Instead, the pipeline has three dependent stages:Google News RSS | vScore every headline | vKeep the top three | vChoice selects one article | vNoul decides whether to investigate | vScrape selected article onlyThis makes each result meaningful and keeps the control flow explicit.Project setupInstall the dependencies used by the example:uv add typesafe-sdk python-dotenv feedparserStore the API key in the project .env file. The example accepts either variable name:TYPESAFE_API_KEY=your-keyNever commit the .env file or print the API key.Imports and configurationfrom pathlib import Pathfrom os import getenvimport jsonimport sysfrom dotenv import load_dotenvfrom typesafe_sdk import Choice, Noul, NoulCriteria, Score, TypeSafeClientPROJECT_ROOT = Path.cwd().parentload_dotenv(PROJECT_ROOT / ".env")TYPESAFE_API_KEY = getenv("TYPESAFE_API_KEY") or getenv("TYPESAFE_KEY")MODEL = "jev-latest"SRC_ROOT = PROJECT_ROOT / "src"if str(SRC_ROOT) not in sys.path: sys.path.insert(0, str(SRC_ROOT))from tools.get_google_news import get_newsThe local get_news helper returns dictionaries with this shape:{ "title": "Article headline", "link": "https://...", "published": "...", "source": "Publisher",}Step 1: fetch current headlinesFor this example, the user asks a simple question about pollution:user_question = "What are the latest developments in reducing air pollution?"articles = get_news( "latest air pollution reduction technology policy", when="30d", limit=8,)print("Fetched", len(articles), "articles")for index, article in enumerate(articles): print(f"{index}: {article['title']}") print(f" {article['source']} | {article['published']}")At this stage, we have metadata only. We have not downloaded article bodies. That is intentional: headlines are cheap to collect, while article scraping is a more expensive operation.Step 2: create a JSON-friendly article stateJev can work with structured state. Convert the list into named article records so the model can compare them:article_options = { f"article_{index}": { "title": article["title"], "source": article.get("source", "Unknown source"), } for index, article in enumerate(articles)}print(json.dumps(article_options, indent=2, ensure_ascii=False))The state contains the articles. The question itself belongs in the instructions field. Keeping these separate avoids duplicating the same information in both places.Step 3: score every articleA Score is a good fit for ranking because relevance has an order:score_criteria = [ { "summary": "Irrelevant", "signals": ["Unrelated to the question."], }, { "summary": "Possibly related", "signals": ["Mentions pollution but not the requested reduction angle."], }, { "summary": "Relevant", "signals": ["Addresses an important part of the question."], }, { "summary": "Highly relevant", "signals": ["Directly discusses a credible reduction technology or policy."], },]score_questions = { f"article_{index}_relevance": Score( instructions={ "question": "How relevant is this article title to the user's question?", "user_question": user_question, "article": article_options[f"article_{index}"], "field": "article.title", "focus": "Judge the headline only. Do not assume facts not present in the title.", }, criteria=score_criteria, ) for index in range(len(articles))}with TypeSafeClient(api_key=TYPESAFE_API_KEY) as client: score_response = client.system_one( model=MODEL, state={"articles": article_options}, questions=score_questions, )score_answers = score_response.answersarticle_scores = { article_id: { "score": score_answers[f"{article_id}_relevance"].score, "confidence": score_answers[f"{article_id}_relevance"].confidence, "probabilities": score_answers[f"{article_id}_relevance"].probabilities, } for article_id in article_options}All score questions are evaluated in one request. The results can now be ranked in ordinary Python:shortlist_ids = sorted( article_scores, key=lambda article_id: article_scores[article_id]["score"], reverse=True,)[:3]shortlist = { article_id: article_options[article_id] for article_id in shortlist_ids}print("Shortlist:")for article_id in shortlist_ids: print(article_id, article_scores[article_id]["score"]) print(shortlist[article_id]["title"])Python performs the mechanical ranking. Jev is used for semantic judgment, not for sorting dictionaries or tracking indexes.Step 4: use Choice on the shortlistNow use Choice to select one article from the top three:choice_question = Choice( instructions={ "question": "Which shortlisted article should be investigated first?", "user_question": user_question, "field": { "name": "title", "type": "string", "description": "The headline returned by the news search.", }, "focus": "Choose the strongest article from the relevance-based shortlist.", "do_not_use": "Do not choose based on source popularity or URL.", }, criteria=shortlist,)with TypeSafeClient(api_key=TYPESAFE_API_KEY) as client: choice_response = client.system_one( model=MODEL, state={"shortlisted_articles": shortlist}, questions={"best_article": choice_question}, )best_article_answer = choice_response.answers["best_article"]selected_article_id = best_article_answer.choiceselected_index = int(selected_article_id.rsplit("_", 1)[-1])selected_article = articles[selected_index]print("Selected:", selected_article["title"])print("URL:", selected_article["link"])The shortlist is important. Passing every result to Choice makes the model compare more candidates than necessary and allows weak, loosely related headlines to compete with strong ones.Step 5: gate scraping with NoulThe final question is binary: should the selected headline be investigated further?selected_title = selected_article["title"]investigation_question = Noul( instructions={ "question": "Is the selected article worth investigating further?", "user_question": user_question, "selected_article": { "title": selected_title, "source": selected_article.get("source", "Unknown source"), }, "field": "selected_article.title", "focus": "Evaluate the title only, before scraping the article body.", }, criteria=NoulCriteria( true={ "what": "Directly relevant and likely to contain useful evidence.", }, false={ "what": "Vague, unrelated, or only tangentially connected.", }, ),)with TypeSafeClient(api_key=TYPESAFE_API_KEY) as client: investigation_response = client.system_one( model=MODEL, state={ "selected_article": { "title": selected_title, "source": selected_article.get("source", "Unknown source"), }, }, questions={"should_investigate": investigation_question}, )should_investigate = investigation_response.answers["should_investigate"].noulif should_investigate >= 0.8: print("Scrape the selected article:", selected_article["link"])elif should_investigate print("Skip the article")else: print("Send the selection for manual review")The threshold is application policy, not a property of Jev. A production system might use a higher threshold when scraping is expensive or when false positives are costly.Raw and structured JSON outputThe SDK response object itself is not directly JSON serializable. Extract its model data first:def response_to_json_data(response): if hasattr(response, "model_dump"): return response.model_dump() if hasattr(response, "to_dict"): return response.to_dict() if hasattr(response, "dict"): return response.dict() return {"answers": {key: vars(answer) for key, answer in response.answers.items()}}raw_typesafe_response = { "score_response": response_to_json_data(score_response), "choice_response": response_to_json_data(choice_response), "noul_response": response_to_json_data(investigation_response),}print(json.dumps(raw_typesafe_response, indent=2, default=str))For an application-facing response, create a smaller structure that contains only the fields your API needs:structured_output = { "question": user_question, "articles": [ { "id": f"article_{index}", "title": article["title"], "source": article.get("source", "Unknown source"), "score": article_scores[f"article_{index}"], "shortlisted": f"article_{index}" in shortlist_ids, } for index, article in enumerate(articles) ], "selection": { "article_id": selected_article_id, "confidence": best_article_answer.confidence, "probabilities": best_article_answer.probabilities, }, "selected_article": { "title": selected_article["title"], "source": selected_article.get("source", "Unknown source"), "published": selected_article.get("published"), "url": selected_article["link"], }, "investigation": { "yes_probability": should_investigate, },}print(json.dumps(structured_output, indent=2, ensure_ascii=False, default=str))Example responseThe raw TypeSafe responses contain model metadata, token usage, and typed answers. A shortened example looks like this:{ "score_response": { "model": "jev-1.13.0", "usage": { "input_tokens": 1200, "output_tokens": 90 }, "answers": { "article_0_relevance": { "type": "score", "score": 2.4, "confidence": 0.78, "probabilities": { "0": 0.0, "1": 0.05, "2": 0.55, "3": 0.40 } } } }, "choice_response": { "model": "jev-1.13.0", "answers": { "best_article": { "type": "choice", "choice": "article_0", "confidence": 0.91, "probabilities": { "article_0": 0.91, "article_2": 0.06, "article_5": 0.03 } } } }, "noul_response": { "model": "jev-1.13.0", "answers": { "should_investigate": { "type": "noul", "noul": 0.86 } } }}The application-facing response can then be smaller and easier for a downstream service to consume:{ "question": "What are the latest developments in reducing air pollution?", "articles": [ { "id": "article_0", "title": "Coordinated action on clean air and climate change can net $15 for every dollar spent", "source": "United Nations", "score": { "score": 2.4, "confidence": 0.78, "probabilities": { "0": 0.0, "1": 0.05, "2": 0.55, "3": 0.40 } }, "shortlisted": true } ], "selection": { "article_id": "article_0", "confidence": 0.91, "probabilities": { "article_0": 0.91, "article_2": 0.06, "article_5": 0.03 } }, "selected_article": { "title": "Coordinated action on clean air and climate change can net $15 for every dollar spent", "source": "United Nations", "url": "https://news.google.com/rss/articles/example" }, "investigation": { "yes_probability": 0.86 }}Because the Noul value is 0.86, the example application would continue to article scraping. In a real run, the title, URL, probabilities, and token usage will change with the current news results.Response from each stageFor debugging and observability, it is useful to inspect the response after every stage instead of printing only the final object.Stage 1: news search responseThe news helper returns a list of article metadata:[ { "title": "Coordinated action on clean air and climate change can net $15 for every dollar spent", "link": "https://news.google.com/rss/articles/example-0", "published": "Wed, 09 Sep 2026 07:00:00 GMT", "source": "United Nations" }, { "title": "Union Environment Minister reviews air pollution action plan", "link": "https://news.google.com/rss/articles/example-1", "published": "Fri, 18 Sep 2026 11:04:00 GMT", "source": "PIB" }]At this point, no Jev call has been made.Stage 2: article options sent to JevThe list is converted into a keyed JSON object so every article has a stable identifier:{ "article_0": { "title": "Coordinated action on clean air and climate change can net $15 for every dollar spent", "source": "United Nations" }, "article_1": { "title": "Union Environment Minister reviews air pollution action plan", "source": "PIB" }}Stage 3: Score responseThe first Jev request scores every article independently. A shortened response looks like this:{ "answers": { "article_0_relevance": { "type": "score", "score": 2.4, "confidence": 0.78, "probabilities": {"0": 0.0, "1": 0.05, "2": 0.55, "3": 0.40} }, "article_1_relevance": { "type": "score", "score": 2.1, "confidence": 0.69, "probabilities": {"0": 0.0, "1": 0.12, "2": 0.55, "3": 0.33} } }}The application uses the numeric score values to rank the articles:article_0: 2.4article_1: 2.1Stage 4: shortlist responsePython keeps the highest-scoring candidates. This stage does not call Jev:{ "article_0": { "title": "Coordinated action on clean air and climate change can net $15 for every dollar spent", "source": "United Nations" }, "article_1": { "title": "Union Environment Minister reviews air pollution action plan", "source": "PIB" }}Stage 5: Choice responseThe shortlist is sent to a second Jev request. Choice selects one candidate:{ "answers": { "best_article": { "type": "choice", "choice": "article_0", "confidence": 0.91, "probabilities": { "article_0": 0.91, "article_1": 0.09 } } }}The application uses article_0 to recover the original article record and its URL.Stage 6: Noul responseFinally, only the selected article is passed to Noul:{ "answers": { "should_investigate": { "type": "noul", "noul": 0.86 } }}The application can now apply a simple policy:if noul_value >= 0.8: scrape_article(selected_article["link"])elif noul_value skip_article(selected_article)else: send_to_manual_review(selected_article)What this pattern gets rightThe pipeline gives each primitive a clear responsibility:Score answers: "How relevant is each candidate?"Python answers: “Which candidates make the shortlist?”Choice answers: "Which shortlisted candidate is best?"Noul answers: "Should the system take the next action?"It also respects the dependency boundaries between calls. The Choice call cannot know the result of a Score call unless the application passes the shortlist into a later request. Likewise, Noul should run after the selected article exists.For a production version, the next step would be to call the repository’s scrape_article tool only when the Noul probability clears the configured threshold, then pass the scraped body to a separate answer-generation or extraction stage.Building a News Article Triage Pipeline with Jev and Python was originally published in Towards AI on Medium, where people are continuing the conversation by highlighting and responding to this story.